Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE HELP GUYS 34 PYTHON QUESTIONS YOU CAN ANSWER SOME OR ALL, I DONT WANT TO FAIL THE CLASS I WILL THUMBS UP! 2. How

PLEASE HELP GUYS 34 PYTHON QUESTIONS YOU CAN ANSWER SOME OR ALL, I DONT WANT TO FAIL THE CLASS I WILL THUMBS UP!

2. How many times the phrase "print until 1 million" will be printed by the code segment below?

x = 0

while (True):

x

+= 1

print("print

until 1 million")

3. How will you modify the range() function in the for ... loop below so it will print every other number between 0 and 100?

for i in

range(0,100):

print(i)

4. The sorting algorithm we learned in this course is called ______ which is simple, easy to implement but not so efficient.

5. The program below has an obvious syntax error. Make the correction by rewriting the line in error.

// My First

Python Program

major = "CIS"

print(major)

6. fname = "Quinton"

lname = "Ross"

Write a print() statement

to print the person's full name as "Ross, Quinton".

7. dept = ("ACT", "FIN", "CIS", "MGT", "MKT")

Consider the tuple above, write the necessary code (e.g., a for ...

loop) to print the individual tuple elements in separate lines.

8. Consider the string variable below

dept = "CIS"

Suppose we would like to print out the string letter by letter

and separate them by a space,

like "C I S ". How would you modify/correct the print()

statement in the following for... loop?

for c in dept:

print(c)

9. Write a statement to declare the tuple variable named state which has 4 members - " Alabama", "Georgia",

"Florida", and "Mississippi".

10. employee = ['Donald Trump', 1946, 'President', 2016, 2020]

Write a print()

statement to print out the entire contents of employee.

11. Suppose we have the following variable declaration:

dept = {"ACT":

1, "FIN": 2, "CIS": 3, "MGT": 4, "MKT": 5}

Write a statement to print the value (i.e., 3)

that associates with "CIS".

12. employee = ['Donald Trump', 1946, 'President', 2016, 2020]

Write a statement to add a new item/member ('White House') to employee so

it will have the following contents:

employee =

['Donald Trump', 1946, 'President', 2016, 2020, 'White House']

13. employee = ['Donald Trump', 1946, 'President', 2016, 2020]

Write a statement to change the value 'Donald Trump' to 'Bill Gates' in employee so

it will have the following contents:

employee =

['Bill Gates', 1946, 'President', 2016, 2020]

14. class myClass():

def

say_hello(self):

print("Hello")

def

say_goodbye(self):

print("Goodbye")

me = myClass()

Write a statement to use object me to

call a function so "Goodbye" will

be printed.

15. class myClass():

def

say_hello(self):

print("Hello")

def

say_goodbye(self):

print("Goodbye")

class

yourClass(myClass):

def

say_nothing(self):

print("Quite")

you =

yourClass()

Write a statement to use object you to

call a function so "Hello" will

be printed.

16. Write the necessary code to swap the values of 2 variables. For example,

suppose A is

10 and B is

20,

we would like to swap the 2 values so A will

have B's

original value 20

and B will

have A's

original value 10.

17. Suppose we have used the variable outFile to open a file named cis300.tst for writing. Write a statement to print your full

name to the file.

18. Write a statement to open the file named "cis300.tst" for reading.

19. Write a statement to open the file named "cis300.tst" for appending and let the computer creates a new file if it does not exist.

20. What an if...else... statement to print "Stay Home" if the value of variable covid is greater than or equal to 19, or print "Stay Well" if covid is less than 19.

21. Suppose x is equal to your last name, what will be printed by the following code segment?

x =

____________________

if (x <=

"Gates"):

print("millionair")

elif (x <=

"Trump"):

print("politician")

else:

print("asu

graduate")

22. Python, Java = 300, 304

if (Python

< Java):

print("%d

is better than %d" % ("Python", "Java"))

Modify/correct the print()

statement in thecode segment above so it will print

Python is

better than Java

23. What will be the result of running the code segment below?

Python = 300

Java = 304

if (python

< java):

print("Python

is a better language")

24. How many times "OK" will be printed by the loop below?

for i in range(0,10000):

if (i % 100 == 0):

print("OK")

25. How many times "OK" will be printed by the loop below?

for n in range(0,100):

for m in range(1,50+1):

print("OK")

26. Suppose we have the following function in our program which will calculate the square of a number.

def square(num):

return num*num

Write a statement to print the square of 300 by calling the

function square().

27. Suppose we would like to print a floating-point number in the format xxxx.xxxx (i.e., 4 digits in the integer portion and 4 decimal places). What formatting specifier (i.e., %x.xf) should we use?

28. What statement ( ______ ) should be used in the code segment below so the loop will stop when x value is300?

x = 999

while (True):

if

(x == 300):

____________________

print(x)

x

-= 1

29. employee = ['Donald Trump', 1946, 'President', 2016, 2020]

The above Python variable employee is

a(n)

30. employee = \['Donald Trump', 1946, 'President', 2016, 2020\]

The value 2020 in employee has an index of _____

31. What statement should be used in the code segment below to print all even numbers between 1 and 10?

for n in range(1,10+1):

if (n % 2 != 0):

_____

print(n)

32. A Python dictionary is used to map or associate things you want to store and the keys you need to get them. The variable age shown below is an example.

age = {'Bill': 18, 'Jim': 21, 'Donald': 73, 'Jean': 25}

What will be printed by the following code segment? _____

print(age\['Donald'\])

33. Python supports several file and directory related build-in functions, such as path.isfile and path.exists. However, before we use any of these functions the _____ library module must be imported.

34. What will be printed by the following code segment? ______

x = 300

if (x <= 300):

print("good")

elif (x == 300):

print("bad")

else:

print("ugly")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions