Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def intro():
- print("Lets do some coding!")
- def doAddSub(command):
- print("lets " + command + " some numbers")
- input1 = input("Number 1> ")
- input2 = input("Number 2> ")
- number1 = int(input1)
- number2 = int(input2)
- if command == "add":
- result = number1 + number2
- operator = " + "
- elif command == "subtract":
- result = number1 - number2
- operator = " - "
- output = str(result)
- print (input1 + operator + input2 + " = " + output)
- def doAvgTot(command):
- # Data collection - include running total
- input1 = input( "Enter the number of numbers you would like to " + command + ": ")
- n = int(input1)
- i = 0
- total = 0
- for i in range(n):
- num = input("Enter number " + str(i) +": ")
- total += int(num)
- if command == "average": # Calculate average
- result = total / n
- else:
- result = total
- # Provide results to user
- print ("The average of your numbers is: " + str(result) + ".")
- finished = False
- while finished==False:
- phrase = input ("Talk to me > ")
- total = 0
- if phrase == "hi" or phrase == "hey" or phrase == "hello":
- print( "hello")
- elif phrase == "whats your name" or phrase == "what's your name":
- print("Marvin")
- elif phrase == "exit" or phrase == "quit":
- exit;
- elif phrase == "quiz":
- while phrase != "exit" and phrase != "quit":
- phrase = input("What is 1 + 3? ")
- if int(phrase) == 4:
- print ("Correct!")
- break
- else:
- print ("Incorrect - please try again!")
- elif phrase == "average" or phrase == "total":
- doAvgTot(phrase)
- elif phrase == "discount":
- discount = int( input("Please enter the percentage discount: "))
- cost = int( input( "Please enter the item(s) cost: "))
- print ("disc: " + str(discount) + " cost: " + str(cost) + " tot: " + str(total))
- total = cost - (float(discount)*float(cost)/100)
- print("Your " + str(discount) + "% discount of " + str(cost) + " is: " + str(total))
- elif phrase == "add" or phrase == "subtract":
- doAddSub(phrase)
- elif phrase == "bye":
- finished = True
- else:
- print( "Sorry, I don't understand " + "'" + phrase +"'.")
- print ("bye")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement