Task - Control-Flow Statements - Unconditional Statements - break - Practice Problems #5
Replies: 11 comments 1 reply
-
1. WAP to print using nested for-loop and break# Nested for-loop and break
def main():
for i in range(5):
for j in range(2):
print(f"({i},{j})")
if j > 1:
break
# run main
main() 2. WAP to ask for the favorite color and quit# favorite color
def main():
print("-- Help: type 'quit' to exit --")
while True:
color = input("What's your favorite color?")
if color.lower() == 'quit':
break
print(f"Your favorite color is: {color}.")
# run main
main() |
Beta Was this translation helpful? Give feedback.
-
for i in range(0,5):
for j in range(0,5):
print("(", i, ", ",j,")")
if(j == 1):
break print("-- Help: Type quit to exit --")
while(True):
inp = input("Enter your favorite color\n>")
if(inp.lower() == "quit"):
break |
Beta Was this translation helpful? Give feedback.
-
1. WAP to print using nested for-loop and breakfor i in range (0,5):
for j in range (0,3):
print("(" + str(i) + "," + str(j) + ")")
if j == 1:
break 2. WAP to ask for the favorite color and quitdef ask():
while True:
color = input("What's your favorite color?")
if color.lower() == "quit":
break
print("Your favorite color is:", color)
ask() |
Beta Was this translation helpful? Give feedback.
-
Name: Francisco Zenteno Task 1. for i in range(0,5):
for j in range(0,5):
print("(",i,",",j,")")
if(j==1):
break Task 2 print("-- Help: type quit to exit --")
while True:
x = input("Enter your favorite color:")
if(x=='quit'):
break |
Beta Was this translation helpful? Give feedback.
-
Task 1def task():
for i in range(0, 5):
j = 0
while(1):
#Break out of the loop
if j == 2: break
print("(", i, ",", j, ")")
j += 1
#Main Method
task() Task 2def task2():
#Infinite loop until quit is entered
while(1):
opc = input("Enter your favorite color:")
if opc == "quit": break
#Main Method
task2() |
Beta Was this translation helpful? Give feedback.
-
Q1 for i in range(5):
for k in range(5):
if(k == 2):
break
print("( " + str(i) + "," + str(k) + " )") Q2 quit = False
while quit == False:
print("--Help: type quit to exit -- \nEnter your favorite color: ")
color = input()
if color == "quit":
quit == True
break
print(color) |
Beta Was this translation helpful? Give feedback.
-
1.- def main():
for i in range(5):
for j in range(5):
if j > 1:
break
print("(" + str(i) + "," + str(j) + ")")
main() 2.- def main():
print("-- Help: type quit to exit --")
while True:
color = input("Enter your favorite color:")
if color == "quit":
break
main() |
Beta Was this translation helpful? Give feedback.
-
#nested loop for i in range (3):
for j in range (3):
print(i,j)
if j==i:
break`` #while loop keep_going = True
while keep_going:
colour = input('Enter your favorite colour, or type quit to exit ')
if colour == "quit":
keep_going = False |
Beta Was this translation helpful? Give feedback.
-
for i in range (0,5):
for j in range (0,2):
print("(", i, ",", j, ")")
if j == 2:
break |
Beta Was this translation helpful? Give feedback.
-
1.- for i in range(5):
for j in range(2):
print(f"({i}),({j})")
if i == 4:
break 2.- print("-- Help: type 'quit' to exit --")
while True:
ans = input("Enter your favorite color: ")
if ans.lower() == 'quit':
break |
Beta Was this translation helpful? Give feedback.
-
for x in range (7):
for y in range (7):
if x==y:
print(x,y)
break
2.Color check while True:
color = input("Enter your favoret color: ")
if (color =='quit'):
break
print(color) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
WAP to print the following output using a nested for-loops and a break statement.
WAP to ask the user for their favorite color and quit only when the user types "quit" using the
break
statement.Example Output:
Beta Was this translation helpful? Give feedback.
All reactions