input in python

Solutions on MaxInterview for input in python by the best coders in the world

showing results for - "input in python"
Andrea
17 Apr 2017
1name = input("What is your name?\n") # Asks the user 'What is your name?' and stores it in the 'name' variable
2
3print("You said your name was " + name)
4
5number = int(input("Please select a random number:\n")) # Will get input as a number
6# Will error if the value entered is not a number
7
8# You can use any type of conversion (int(), bool(), float(), etc.) to modify your input
9
10
Valeria
22 Jan 2018
1# First, let's start with a simple input function.
2input("What's your name?: ") #This will ask you what is your name, and you can input anything you want.
3#The above code is simple, and theres not much you can do with it.
4
5# Let's get a little harder!
6name = input("What is your name? ") # Just adding a variable doesn't look like much, but it goes a long way!
7print("Hello," , name , ", I'm dad!") # THis will print Hello [your name] I'm dad when the user inputs a name.
8
9# Let's make this a little more advanced!
10name = input("What is your name? )
11if name == "Dad": # Now if sombody inputs 'Dad' as there name:
12	print("Hi dad I'm- wait a minute...") # it will say this
13else: # If a user prints anything else:
14	print("Hi" , name , "I'm dad!") # It will output this!
15
16# What if I want to add multiple names? Well, that's entirly possible, with the elif statment
17if name == "Dad": # If the user inputs "Dad" as their input:
18	print("Hi Dad, I'm- stop trying to trick me D:<") # It will output this
19elif name == "Doggo": # If the name is "Doggo":
20	print("Hi doggo- wait your not supposed to talk?") # It will output this:
21# Using the elif statment, we can make an entirley different with only one question asked
22else:
23	print("Hello, ", name, "!") # We always end an if statment with an else one.
24
25# Hope this helped! :D
Sohan
03 May 2017
1#Input in python
2name = input('What is your name')
3print('Hello'+ name + ' !')
Ophélie
17 Jan 2021
1x = input()
2# This will take you to shell where you input a value for x
3
4print(x)
5# Print's the value you typed
6
7y = input('Enter a number: ')
8# Will print 'Enter a number: ' to the shell and then wait for you
9# to enter a value (Does not have to be a number)
10
11# Copy the code and try it
Niklas
09 Jul 2017
1#input or question, is used to ask question
2
3ans = input('Who invented Microsoft?')
4
5#An if statement
6
7if(ans == 'Bill Gates'):
8  print('You got the answer')
Alessia
06 Jul 2016
1l=list(map(int,input().split()))
Giuseppe
13 Jan 2021
1age = input("Your age: ")
2print("Your age is: " + age)
3
4# defines input as a string and prints it out