Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

python for computer science students, Exercises of Computer Science

it is very intersting document please enjoy it

Typology: Exercises

2021/2022

Uploaded on 03/07/2023

gech-deb
gech-deb 🇺🇸

4 documents

1 / 2

Toggle sidebar

Related documents


Partial preview of the text

Download python for computer science students and more Exercises Computer Science in PDF only on Docsity! 1/23/23, 3:38 PM python-for-everybody/wk3 - quiz.py at master · ed-lau/python-for-everybody · GitHub https://github.com/ed-lau/python-for-everybody/blob/master/wk3 - quiz.py 1/2 Question 1 What do we do to a Python statement that is immediately after an if statement to indicate that the statement is to be executed only when the if statement Begin the statement with a curly brace { Start the statement with a "#" character Indent the line below the if statement Underline all of the conditional code Answer: Indent the line below the if statement Question 2 Which of these operators is not a comparison / logical operator? = < == >= > Answer: = Question 3 What is true about the following code segment: if x == 5 : print('Is 5') print('Is Still 5') print('Third 5') Depending on the value of x, either all three of the print statements will execute or none of the statements will execute The string 'Is 5' will always print out regardless of the value for x. The string 'Is 5' will never print out regardless of the value for x. Only two of the three print statements will print out if the value of x is less than zero. Answer: Depending on the value of x, either all three of the print statements will execute or none of the statements will execute Question 4 When you have multiple lines in an if block, how do you indicate the end of the if block? You de-indent the next line past the if block to the same level of indent as the original if statement You put the colon : character on a line by itself to indicate we are done with the if block You use a curly brace { after the last line of the if block You capitalize the first letter of the line following the end of the if block Answer: You de-indent the next line past the if block to the same level of indent as the original if statement Question 5 You look at the following text: if x == 6 : print('Is 6') print('Is Still 6') print('Third 6') It looks perfect but Python is giving you an 'Indentation Error' on the second print statement. What is the most likely reason? Python has reached its limit on the largest Python program that can be run Python thinks 'Still' is a mis-spelled word in the string You have mixed tabs and spaces in the file In order to make humans feel inadequate, Python randomly emits 'Indentation Errors' on perfectly good code - after about an hour the error will just go a Answer: You have mixed tabs and spaces in the file Question 6 What is the Python reserved word that we use in two-way if tests to indicate the block of code that is to be executed if the logical test is false? toggle switch else A closing curly brace followed by an open curly brace like this }{ Answer: else Question 7 What will the following code print out? x = 0 if x < 2 : print('Small') elif x < 10 : print('Medium')
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved