Test 1

¡Supera tus tareas y exámenes ahora con Quizwiz!

1. What would be the following display? A = 5 B = 2 C = 3 Result = a + b * c Print(result)

11

1. What will the following statement display? Print('George', 'John', 'Paul', 'Ringo', sep='@')

George@John@Paul@Ringo

1. Rewrite the following statements using augmented assignment operators. a. X = x +1 b. X = x * 2 c. X = x / 10 d. X = x - 100

a. X += 1 b. X *= 2 c. X /= 10 d. X -= 100

1. Write Python code that prompts the user to enter his or her favorite color assigns the users input to a variable named color

color = input('Enter your favorite color: ')

1. Write a for loop that displays the following set of numbers: 0, 10, 20, 30, 40, 50 . . . 1000

for number in range(0, 1001, 10): print(number)

1. Write a Python code that prompts the user to enter his or her height and assigns the user's input to a variable named height

height = int(input('Enter your height: '))

1. Write nested decisions structures that perform the following: if amount1 is greater than 10 and amount2 is less than 100, display the greater amount1 and amount2

if amount1 > 10 and amount2 < 100: if amount1 > amount2: print (amount1) elif amount2 > amount1: print (amount2) else: print('Both values are the same.')

1. Write an if-else statement that determines whether the points variable is outside the range of 9 to 51. If the variable's value is outside this range it should display "Invalid Points." Otherwise, it should display "Valid points."

if points < 9 or points > 51: print ('Invalid points') else: print ('Valid points')

1. The following code contains several nested if-else statements. Unfortunately, it was written without proper alignment and indentation. Rewrite the code and use the proper conventions of alignment and indentation. If score >= A_score: Print('Your grade is A.') Else: If score >= B_score: Print('Your grade is B.') Else: If score >= C_score: Print('Your grade is C.') Else: If score >= D_score: Print('Your grade is D.') Else: If score >= F_score: Print('Your grade is F.')

if score >= A_score: print('Your grade is A.') elif score >= B_score: print('Your grade is B.') elif score >= C_score: print('Your grade is C.') elif score >= D_score: print('Your grade is D.') else: print('Your grade is F.')

1. Write an if statement that assigns 20 to the variable y, and assign 40 to the variable z if the variable x is greater than 100

if x > 100: y = 20 z = 40

1. Write a code that prompts the user to enter a positive nonzero number and validates the input

number = float(input('Enter a positive nonzero number: ')) while number <= 0: print('That is an invalid value.') number = float(input('Enter a positive nonzero number: ')) print ('Thanks!')

1. Assume the variable sales reference a float value. Write a statement that displays the value rounded to two decimal points.

print(format(sales, '.2f))

1. Write a while loop that lets the user enter a number. The number should be multiplied by 10, and the results assigned to a variable named product. The loop should iterate as long as product is less than 100

product = 0 while product < 100: number = int(input('Enter a number: ')) product = number * 10

1. Write a loop that asks the user to enter a number. The loop should iterate 10 times and keep running total of the numbers entered

total = 0.0 for counter in range(10): number = float(input('Enter a number: ')) total += number print ('The total is', total)

Write a python statement that assigns the sum of 10 and 14 to the variable total

total = 10 + 14


Conjuntos de estudio relacionados

ENDO pt 1: Diabetes - Endocrine Clinical Assessment and Diagnostic Procedures

View Set

Life Insurance Basics: PA Life and Health Exam

View Set

Change Theory and Elements of Change

View Set

TX Principles of Real Estate I Exam

View Set

AP1E2, AP1 Exam 3, Endocrine Hormones

View Set

AP Environmental Science | Chapter 18: Conservation of Biodiversity

View Set