CS1101 - Unit 5 Questions With 100% Correct!!
What does function subroutine do? def subroutine( n ): while n > 0: print (n,) n -= 1 - Answer-Counts from n down to 1 and displays each number What output will the following python command produce: >>> percentage = float ( 60 * 100) / 55 >>> print (percentage) - Answer-109. What output will the following python commands produce: n = 10000 count = 0 while n: count = count + 1 n = n // 10 print (count) - Answer-5 What output will the following python commands produce: x = 5 if x % 2 == 0: print (x)else: print (x, x%2) - Answer-5 1 What does function subroutine do? def subroutine(n): while n > 0: print (n,) n -= 1 - Answer-Counts from n down to 1 and displays each number What is the output of the following statements? pi = float(3.14159) print (pi) - Answer-3.14159 What is the output of the following statements? pi = int(3.14159) print (pi) - Answer-3 Expressions evaluate to either true or false. What will the output of the following code be when the expression "Ni!" is evaluated? if "Ni!": print ('We are the Knights who say, "Ni!"') else: print ("Stop it! No more of this!") - Answer-We are the Knights who say, "Ni!" What output will the following python commands produce:x=1 y=2 if x == y: print (x, "and", y, "are equal") else: if x < y: print (x, "is less than", y) else: print (x, "is greater than", y) - Answer-1 is less than 2 The following code is an example of what principle? bruce = 5 print (bruce,) bruce = 7 print (bruce) - Answer-Multiple assignment True/False: The % or modulus operator returns the remainder present when two integers do not divide evenly into one another - Answer-True True/False: An algorithm is a step by step process for solving a problem. - Answer-True Functions allow the programmer to encapsulate and generalize sections of code. - Answer-True One way to generalize a function is to replace a variable with a value. - Answer-False A variable name defined in a function cannot appear in the calling program because it will cause a conflict error. - Answer-False
Written for
- Institution
- CS1101 - Unit 5
- Course
- CS1101 - Unit 5
Document information
- Uploaded on
- May 7, 2024
- Number of pages
- 3
- Written in
- 2023/2024
- Type
- Exam (elaborations)
- Contains
- Questions & answers
Subjects
Also available in package deal