Thursday, September 27, 2018

First Python

First console

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> print("Hello")
Hello
>>> name = 'Steve'
>>> print("hello, ",name)
hello,  Steve
>>> name=input("Enter your name: ")
Enter your name: Bob
>>> print ("Hello,",name)
Hello, Bob
>>> 

Hello Bob Program

#This program takes a name as input
#and outputs a greeting
#steve C 9/27/2018

#input
#process (algorithm) --
#def of algorithm--steps needed to accomplish a task
# in the order that they need to be taken
# take inputs and turn them into outputs
#output

def main():
    #get the input
    name = input('Enter your name: ')
    # print the text and variable
    print('Hello,',name)

#call main
main()

Cube program

# user enter an integer
# output a cube of that integer
# When using numbers use eval or number type int float
def main():
    number = float(input("Enter an integer: "))
    cube=number * number * number
    print("The cube is",cube)

main()

Chaos program with additional input for user to determine number of loops

# chaos program (page 13)

def main():
    print('This program illustrates a chaotic function')
    x=float(input('Enter a number between 0 and 1: '))
    y=int(input('Enter the number of loops '))
    for i in range(y):
        x=3.9 * x *(1-x)
        print(i,x)

    

main()
            

No comments:

Post a Comment