You are to write a program in Python and name it lab7python.py Your program shou
ID: 3845252 • Letter: Y
Question
You are to write a program in Python and name it lab7python.py Your program should start by asking you your name. Make sure that a name is entered (no empty string is read in). It should then gather another 5 pieces of information about you. Make sure that some information is entered each time (no empty string is read in). All information gathered must be stored in variables. Two or three of the pieces of information gathered must be numerical and stored as numbers. Your program should then print out the information it has gathered, in the same exact way it was entered. Your program should next ask you to login and play a game of guess the number. If a legit login is entered you will be allowed 10 guesses. If a legit login is not entered, you are logged in as a guess and only have 5 guesses. Each time the user makes a guess the program indicates if the next guess should be lower or higher. End your program indicated if the number was guesses correctly or not.
Explanation / Answer
nm=input("Enter the name ") #aapting input from the user
city=input("Enter the city ")
roll=input("Enter the roll ")
sub=input("Enter the subject ")
mark=input("Enter the marks ")
print " "
print "Name : ",nm #printing the details
print "City : ",city
print "Roll : ",roll
print "Subject : ",sub
print "Marks : ",mark
print " "
login=input("Enter your login id") #asking the user id
print " "
if login==nm: #if user id matches it will be 10 chances
ch=10
print "Welcome to the Guess Game"
print "You Have to Guess your Roll Number"
print "You have ",ch," chances"
while(ch!=0):
tp=input("Guss your roll ")
if tp==roll:
print "You have guessed the right roll!!!"
print "Congratulation"
break
elif tp<roll:
print "Increase your Guess"
ch=ch-1
else:
print "Decrease your Guess"
ch=ch-1
print "YOu have used all your chances"
else: #if user id doesnot matches it will be 5 chances
ch=5
print "Welcome to the Guess Game"
print "You Have to Guess your Roll Number"
print "You have ",ch," chances"
while(ch!=0):
tp=input("Guss your roll ")
if tp==roll:
print "You have guessed the right roll!!!"
print "Congratulation"
break
elif tp<roll:
print "Increase your Guess"
ch=ch-1
else:
print "Decrease your Guess"
ch=ch-1
print "YOu have used all your chances"
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.