Accepting Input from User
Basic way of accepting input:
input('Please enter your name: ') # Asks user to enter their name
To use that data:
name = input('Please enter your name: ')
print("Hello there " + name)
To prevent the variable from containing the extra spaces:
name = input('Please enter your name: ')
print("Hello there " + name.strip()) # Strip removes spaces
Anything that the user types as input it will be taken as a
STRING
even if it is a number
To do math:
number = input('Enter your number: ')
print(5 + int(number))
Last updated