Getting started (1) Flashcards

1
Q

Write a program that asks the user for a temperature in Celsius, converts it to Fahrenheit and then displays it.

A

temp=int(input(“Enter a temperature in Celsius: “))
print(“The temperature in Fahrenheit is:”, 9/5⁎temp+32)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Write a program that asks the user for two numbers, calculate the average and then displays it.

A

num1=int(input(“Enter the first number: “))
num2=int(input(“Enter the second number: “))
print(“The average of the numbers is:”, (num1+num2)/2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Write a program that asks the user for his/her name and then displays the message “Hello, (name)”.

A

name=input(“Enter your name: “)
print(“Hello,”, name)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Write a program that asks the user for a number, calculates the square of the number and then displays it.

A

num=int(input(“Enter a number: “))
print(“The square of the number is:”, num⁎num)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Write a program that displays the lines “On the first line”, and “On the second line” on the same line. Then, write it so that it writes the two lines on two different lines.

A

print(“On the first line”, end=’’)
print(“On the second line”)

print(“On the first line”)
print(“On the second line”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Write a program that asks the user for a temperature in Celsius and converts it to Fahrenheit. Then, it should display the message “The temperature is above the boiling point” if the temperature is above 212, and “The temperature is below the freezing point if the temperature is below 32.

A

temp=int(input(“Enter a temperature in Celsius: “))
f_temp=9/5/⁎temp+32
print(“In Fahrenheit, that is”, f_temp)
if f_temp>212:
print(“That temperature is above the boiling point.”)
if f_temp<32:
print(“That temperature is below the freezing point.”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Write a program that prints a box like the one below.
⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎
⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎
⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎
⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎

A

for i in range(4):
print(“⁎”⁎20)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Write a program that prints a box like the one below.
⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎
⁎ ⁎
⁎ ⁎
⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎⁎

A

print(“⁎”⁎20)
print(“⁎”, “ “⁎16, “⁎”)
print(“⁎”, “ “⁎16, “⁎”)
print(“⁎”⁎20)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Write a program that prints a triangle like the one below.

⁎⁎
⁎⁎⁎
⁎⁎⁎⁎

A

for i in range(4):
print(“⁎”⁎(i+1))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Write a program that calculates the following:
(512-282)/(47⁎48+5)

A

print((512-282)/(47⁎48+5))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Write a program that asks the user for a number, calculates the square of the number and then displays it.

A

num=int(input(“Enter a number: “))
print(“The square of the the number is:”, num⁎num)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Write a program that asks the user for a number x and then displays the following:
x — x⁎2 — x⁎3 — x⁎4 — x⁎5

A

num=int(input(“Enter a number: “))
print(num, “—”, num⁎2, “—”, num⁎3, “—”, num⁎4, “—”, num⁎5)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Write a program that asks the user for a weight in kilograms and then converts it to pounds. (Hint = 2.2)

A

weight=int(input(“Enter a weight in kilograms: “))
print(“The weight in pounds is:”, weight⁎2.2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Write a program that asks the user for 3 numbers, calculates the sum and the average of the numbers and then displays both of them.

A

num1=int(input(“Enter the first number: “))
num2=int(input(“Enter the second number: “))
num3=int(input(“Enter a third number:”))
total=num1+num2+num3
average=(num1+num2+num3)/3
print(“The sum of the numbers is:”, total)
print(“The average of the numbers is:”, average)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Write a program that asks the user for the price of the meal and then for the percent of tip wished to be given. The program should calculate the tip and then display both the price of the meal and the tip. (multiply the tip with the price and divide it by 100)

A

price=int(input(“Enter the price of the meal: “))
tip=int(input(“Enter the prcent tip you wish to leave: “))
tip=(price⁎tip)/100
print(“The price of the meal is:”, price)
print(“The tips is:”, tip)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly