Accepting Input from User
Basic way of accepting input:
input('Please enter your name: ') # Asks user to enter their nameTo 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 spacesAnything that the user types as input it will be taken as a
STRINGeven if it is a number
To do math:
number = input('Enter your number: ')
print(5 + int(number))Last updated