Q. For each of the following, write a single (that is, one) Python statement:


(a) Tell the user to Enter your name, then read in, and assign to a variable, a string typed in by the user.
(b) Tell the user to Enter your age, then read in, and assign to a variable, an integer typed in by the user.
(c) Print out, on separate lines, Your name is name and Your age is age, where name and age are the values of the two variables entered above.


Answer :-

(a)
Program :-
name = input("Enter your Name :- ")
print (str(name))
print (type(name))
Output:-

Enter your Name :- Path Walla
Path Walla
<class 'str'>
>>>
Enter your Name :- Python'
Python'
<class 'str'>
>>>

(b)
Program :-
name = input("Enter your Name :- ")
age = int (input ("Enter your Age :- "))
print (name)
print (age)
print (type(name))
print (type(age))
Output :-

Enter your Name :- Path walla
Enter your Age :- 25
Path walla
25
<class 'str'>
<class 'int'>
>>>
Enter your Name :- Python
Enter your Age :- 64
Python
64
<class 'str'>
<class 'int'>
>>>

(c)
Program :-
name = input("Enter your Name :- ")
age = int (input ("Enter your Age :- "))
print ("Your name is", name, "and Your age is", age)
Output :-

Enter your Name :- Path walla
Enter your Age :- 25
Your name is Path walla and Your age is 25
>>>
Enter your Name :- Python
Enter your Age :- 64
Your name is Python and Your age is 64
>>>

2 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post