training Day3
Tuples
Program to find largest number in list
list = [1,4,8,9,7,4]
x=1
for n in list:
if x > n :
x = n
print(x)
Program to guess a number
guess_count = 1
guess_limit =3
number = 9
while guess_count <= guess_limit :
guess = int(input("Enter the number"))
if(guess == number) :
print("You win")
break
guess_count += 1
else :
print("You failed")
Program for Car game
command = " "
started = False
while True :
command = input("Enter command").lower()
if command == "start":
if started :
print("Car already started")
else:
started = true
print("Car already started")
elif command == "stop":
if not started :
print("Car already stopped")
else:
started = false
print("Car stopped")
elif command = "help" :
print(" "'Start = To start the car
Stop = To stop the car
Quit = To Exit
Help = for help"' ")
elif command == "quit"
break
else:
print("Sorry! I don't understand you")
Note :- In python we can use keyword break to break the loop and else can also be used with wile keyword or while loop.
Comments
Post a Comment