Questin 1
(CO 2) Which of the following is not a valid name in python?
last_name
lastName
last name
lname
Question 2
(CO 3) How many times will “Hello World” be displayed after the
following code executes?
num=2
while num<12:
print("Hello world")
num+=2
2
12
5
4
Question 3
(CO 1) The following code contains an error, what type of error
is it and what line number is it?
1 count=1
2 while count<4
3 print("count = ", count)
4 count+=1
5 print("The loop has ended")
line 1, syntax error
line 5, runtime error
line 2, syntax error
line 4, runtime error
Question 4
(CO 2) After the following code executes, what will be
displayed?
guess=10
if guess<20:
print("Too low")
elif guess>20:
print("Too high")
Too low
Too high
The numbers are equal
nothing will display
Question 5
(CO 1) Given: x=23, y=15
What is the value of new_num after the following statement
executes?
new_num = x%y
1.5333333
1
8
0.533333
Question 6
(CO 1) Which of the following code samples will get a floating point number from the user?
new_number=float input "Please enter a number: "
new_number=input(float("Please enter a number: "))
new_number=float(input("Please enter a number: "))
new_number= input("Please enter a number: ")
Question 7
(CO 3) What will be displayed after the following loop is
run?
sum = 0
for i in range(0, 25, 5):
sum+=i
print(sum)
30
50
0, 5, 10, 15, 20
0, 5, 10, 15, 20, 25
Question 8
(CO 6) To call a function, you code the function name and
nothing
a set of parentheses that contains zero or more arguments
a set of parentheses that contains one or more arguments
a list of local variables
Question 9
(CO 6) The best way to call the main() function of a program is to code
main()
a while statement that calls the main() function in each loop
an if statement that calls the main() function in each method
an if statement that calls the main() function only if the current module is the main module
Question 10
(CO 6) A variable that can only be used within the function that defines it is known as a ______
local variable
global variable
shadow variable
unknown variable
Question 11
(CO 6) Which of the following statements imports a module?
export temperature
import temperature
from temperature import
global temperature import
Question 12
(CO 5) To insert the item “chewie” after “solo” in the following
list, which of the following methods would you use?
falcon = [“han”, “leia”, “solo”, “yoda”, “luke”]
falcon.pop(3,”chewie”)
falcon.remove(3,”chewie”)
falcon.insert(3,”chewie”)
falcon.insert(“chewie”, 3)
Question 13
(CO 5) The ______________ method adds an item to the end of a list.
index()
insert()
pop()
append()
Question 14
(CO 5) Given the following list, what is the value of
names[5]?
names = [“Harry”, “Ron”, “Ginny”, “Draco”, “Rowena” ]
“Harry”
“Rowena”
“Ron”
None – index error
Question 15
(CO 5) What is the value of the total variable after the
following code executes?
prices=[66, 22, 47, 30]
total = 0
i=1
while i<len(prices):
total+=prices[i]
i+=1
print(total)
35
66
0
99
Question 1 last name Question 2 5 Question 3 line 2, syntax error Question 4 Too low Question 5 8 Question 6 new_number=float(input("Please enter a number: ")) Question 7 50 Question 8 a set of parentheses that contains zero or more arguments
Questin 1 (CO 2) Which of the following is not a valid name in python? last_name...
Question 9 (CO 6) The best way to call the main() function of a program is to code main() a while statement that calls the main() function in each loop an if statement that calls the main() function in each method an if statement that calls the main() function only if the current module is the main module Question 10 (CO 6) A variable that can only be used within the function that defines it is known as a ______...
Write a python program write a function numDigits(num) which counts the digits in int num. Answer code is given in the Answer tab (and starting code), which converts num to a str, then uses the len() function to count and return the number of digits. Note that this does NOT work correctly for num < 0. (Try it and see.) Fix this in two different ways, by creating new functions numDigits2(num) and numDigits3(num) that each return the correct number of...
Part 1: Python code; rewrite this code in C#, run the program and submit - include comments number= 4 guesscount=0 guess=int(input("Guess a number between 1 and 10: ")) while guess!=number: guesscount=guesscount+1 if guess<number: print("Your guess is too low") elif guess>number: print("Your guess is too high") else: print("You got it!!") guess=int(input("Guess again: ")) print("You figured it out in ",guesscount," guesses") Part 2: C++ code; rewrite the following code in C#. Run the program and submit. - include comments #include <iostream> using...
Overview Module 3 Assignment 1 features the design of a pseudocode and a Python program that uses iteration to guess a number from 1 to 10. Each lab asks you to write pseudocode that plans the program’s logic before you write the program in Python and to turn in three things: 1) the pseudocode, 2) a screenshot of the output, and 3) the Python program. Instructions Write pseudocode for a Python program that uses iteration to guess a number from...
Can you add code comments where required throughout this Python Program, Guess My Number Program, and describe this program as if you were presenting it to the class. What it does and everything step by step. import random def menu(): #function for getting the user input on what he wants to do print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the...
Number 1) Which of the following statements imports a module into the default namespace? a. from temperature import * b. import temperature as t c. import temperature as temp d. import temperature Number 2) Which of the following statements imports a module into the global namespace? a.from temperature import * b. import temperature as temp c. import temperature as global d. import temperature Number 3) Code Example 4-2 def get_volume(width, height, length=2): volume = width * height * length...
10p Python For the following question, refer to the Python module on the right, as well as the code below. 1) What is the output of the following code? #dodgeable.py #main dodgeable.py import dodgeable class Locatable: def NUM_CARS = 3 init (self,x,y): NUM TRUCKS = 2 self.mX = X WIDTH = 60 self.mY = y def setx (self,x): def main (): self.mX = x object_list = [] def sety (self, y): self.mY = y for i in range (NUM_CARS) :...
Can you please enter this python program code into an IPO Chart? import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the non-numbers #if user enters letters, then except will show the message, Numbers only! try: c=int(input("Enter your choice: ")) if(c>=1 and c<=3): return c else: print("Enter number between 1 and 3 inclusive.") except: #print exception print("Numbers Only!")...
(Java with Netbeans) Programming. Please show modified programming code for already given Main class, and programming for code for the new GameChanger class. // the code for Main class for step number 6 has already been given, please show modified progrraming for Main class and GameCHanger class, thank you. package .games; import java.util.Random; import java.util.Scanner; public class Main { public static void main(String args[]) { System.out.println("Welcome to the Number Guessing Game"); System.out.println(); Scanner sc = new Scanner(System.in); // Get upper...