prmlt python code example

Example 1: input in python

name = input("What is your name?\n") # Asks the user 'What is your name?' and stores it in the 'name' variable

print("You said your name was " + name)

number = int(input("Please select a random number:\n")) # Will get input as a number
# Will error if the value entered is not a number

# You can use any type of conversion (int(), bool(), float(), etc.) to modify your input

Example 2: pythn programme for adding user unputs

# Store input numbers
num1 = input('Enter first number: ')
num2 = input('Enter second number: ')

# Add two numbers
sum = float(num1) + float(num2)

# Display the sum
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))