To allow the user to input values into the program you need to use an input command.
Gathering String Input:
playerName = input("Please enter your name: ")
Gather Number Input: This is important if you want to do a arithmetic calculations on the input.
playerAge = int(input("Please enter your age: "))
OR
playerAge = input("Please enter your age: ")
playerAge = int(playerAge)
Input -Strings and Numbers Video
name = input("Please enter your user name: ")
age = int(input("Please enter your age: "))
print("\n Hi, " + name + ". You are older than me because you are already " + str(age) + " years old.")
Remember when writing an integer to a string through the print function, you need to covert it to string with the function str().
Arithmetic operators can be used to calculate mathematical answers to questions.
Arithmetic can be done between numbers, variables (of appropriate types), and a combination of them.
See examples of arithmetic operation below:
Addition (+)
answer = 10 + 12
answer = num1 + num2
Subtraction (-)
answer = 10 - 2
answer = num1 - num2
Multiplication (*)
answer = 10 * 2
volume = length * width * height
Division ( / )
answer = 50 / 2
fraction = correct / 10
Modulus (%) - returns the remainder of a division of two numbers
#this returns '1'
answer = 3 % 2
A combination of various mathematical operations.
#The result for the calculation below returns a percentage for a quiz
percentageQuiz = (totalCorrect / totalQuestions) * 100
#the result for the calculation below gives the average of three numbers
averageOfThree = (n1 + n2 + n3) / 3