Thursday, September 26, 2019

Python from First Class

First Program

'''
This is a python program
showing some basic elements
Steve 9-26-2019
'''

def main():
    #variables and assignments
    number1 = 7
    number2 = 12

    #print results
    print(number1+number2)

main()
    

Math Operators

'''
This program will ouput some
math based on user inputs
Steve Conger 9-26-2019
'''
def mathOperators():
    #getting input
    nameOfUser=input('Enter your name: ')
    number1, number2 = eval(input("Please enter two numbers divided with a comma: "))
    
    addition =number1 + number2
    subtraction=number1 - number2
    mult = number1 * number2
    division = number1 / number2
    intdivision = number1 // number2
    remainder = number1 % number2 #modulus

    print ("sum",addition)
    print ("difference",subtraction)
    print ("product", mult)
    print("Quotient", division)
    print("integer",intdivision)
    print("remainder", remainder)
    print(nameOfUser)


mathOperators()

Loop

def main():
    word = input("Enter a word")
    for i in range(10):
        print(i, word)

main()

No comments:

Post a Comment