- 1

What is the largest number this code prints?

for i in range (10): if i>5: print (i) break else: print (7) memo states it's 6 But how if when I <5 it should've already printed 7

7th Jun 2017, 11:59 PM
thomo
thomo - avatar
13 odpowiedzi
+ 5
If that is the code and the question was, what is the LARGEST number it prints the answer would be 7. BUT, if the question was what is the LAST number it prints, the answer is 6.
8th Jun 2017, 12:33 AM
Ulisses Cruz
Ulisses Cruz - avatar
+ 4
No, break exits the loop. Plus that's in an else statement. Edit: Nvm I get what you mean, yea 7 would have been printed on the first few i's. Are you sure it didn't say 'last' number?
8th Jun 2017, 12:09 AM
Rrestoring faith
Rrestoring faith - avatar
8th Jun 2017, 12:31 AM
Ulisses Cruz
Ulisses Cruz - avatar
+ 2
What is the largest number this code prints? for i in range(10): if i > 5: print(i) break else: print("7") Answer :- 6
29th Jun 2020, 6:51 AM
Gourav Tomar
Gourav Tomar - avatar
+ 1
What is the sum of the numbers printed by this code? try: print(1) print(1 + "1" == 2) print(2) except TypeError: print(3) else: print(4) Answer :-4
29th Jun 2020, 6:54 AM
Gourav Tomar
Gourav Tomar - avatar
+ 1
Which variable couldn't be accessed if this code was imported as a module? x = 1 y = x if __name__=="__main__": z = 3 Answer :- Z
29th Jun 2020, 6:56 AM
Gourav Tomar
Gourav Tomar - avatar
+ 1
Which of these is a web framework? Answer:- Django
29th Jun 2020, 6:59 AM
Gourav Tomar
Gourav Tomar - avatar
+ 1
Which of these does not convert Python scripts to Windows executables? Answer :- PyExecutable
29th Jun 2020, 7:06 AM
Gourav Tomar
Gourav Tomar - avatar
+ 1
Which variable couldn't be accessed if this code was imported as a module? x = 1 y = x if __name__=="__main__": z = 3 Ans: z
11th Dec 2020, 1:54 PM
Diana Chepkirui
0
You get it but here on solo learn the memo gave wrong for answering 7
8th Jun 2017, 11:36 PM
thomo
thomo - avatar
0
@Rrestoring faith yeah that's the code
8th Jun 2017, 11:39 PM
thomo
thomo - avatar
0
Rearrange the code to print "Welcome" if the script is imported, and "Hi" if it is not imported. Answer :- if __name__== "__main__": print("Hi") else: print("Welcome")
29th Jun 2020, 6:58 AM
Gourav Tomar
Gourav Tomar - avatar
0
Which file is placed in a directory to make it a package? Answer :- __init__.py
29th Jun 2020, 7:02 AM
Gourav Tomar
Gourav Tomar - avatar