python - basic introduction exercise 02

Posted by mikawhat on Sun, 12 Sep 2021 03:40:03 +0200

 

catalogue

1. Title: (Science: wind cold temperature) how cold is it outdoors? Temperature alone is not enough to provide an answer. Other factors: wind speed, relative temperature and light all have a great impact on the outdoor cold degree. Write a program to prompt the user to enter a temperature between - 58 ° F and 41 ° F and a wind speed greater than or equal to 2 miles per hour, and then display the cold temperature.

2. Title: (Physics: calculate the run length) assuming that the acceleration a and take-off speed v of the aircraft are given, calculate the shortest runway length required for aircraft take-off. Write a program to prompt the user to enter v in meter / second (m/s) and a in meter / second square (m/s*s), and then display the shortest run length.

3,   Title: (dividing numbers) write a program to prompt the user to enter four digit integers and display them in reverse order

4. Title: (geometry; triangle area) write a program to prompt the user to input the three vertices (x1,y1), (x2,y2),(x3,y3) of the triangle, and then display its area.

5,   Title: (geometry: area of regular hexagon) write a program to prompt the user to enter the side length of regular hexagon and display its area.

1. Title: (Science: wind cold temperature) how cold is it outdoors? Temperature alone is not enough to provide an answer. Other factors: wind speed, relative temperature and light all have a great impact on the outdoor cold degree. Write a program to prompt the user to enter a temperature between - 58 ° F and 41 ° F and a wind speed greater than or equal to 2 miles per hour, and then display the cold temperature.

Formula:
t(wc)=35.74+0.6215*t(a)-35.75*(v**0.16)+0.4275*t(a)*(v**0.16)
Implementation objectives:
Enter the temperature in Fahrenheit between -58 and 41: 5.3
Enter the wind speed in miles per hour: 6
The wind chill index is -5.56707
code:
ta = float(input("Enter the temperature in Fahrenheit:"))
v = float(input("Enter thee wind speed in miles per hour:"))
twc = 35.74+0.6215*ta-35.75*(v**0.16)+0.4275*ta*(v**0.16)
print("The wind chill index is %.5f" % twc)

Execution results:

2. Title: (Physics: calculate the run length) assuming that the acceleration a and take-off speed v of the aircraft are given, calculate the shortest runway length required for aircraft take-off. Write a program to prompt the user to enter v in meter / second (m/s) and a in meter / second square (m/s*s), and then display the shortest run length.

Formula:
length = (v * v) / (2 * a)
Implementation objectives:
Enter speed and acceleration: 60,3.5
The minimum runway length for this airplane is 514.286 meters
code:
v, a = eval(input("Enter speed and acceleration: "))
length = (v * v) / (2 * a)
print("The minimum runway length for airplane is %.3f meters" % length)

Execution results:

3,   Title: (dividing numbers) write a program to prompt the user to enter four digit integers and display them in reverse order

Implementation objectives:
Enter an integer: 5213
3
1
2
5

code:
num = input("Enter an integer: ")
num1 = tuple(num)
print(num[3])
print(num[2])
print(num[1])
print(num[0])

Execution results:

4. Title: (geometry; triangle area) write a program to prompt the user to input the three vertices (x1,y1), (x2,y2),(x3,y3) of the triangle, and then display its area.

Formula:
s = (side1 + side2 + side3)/2
area = (s*(s-side)(s-side2)(s-side3))**0.5
Implementation objectives:
Enter three points for a triangle: 1.5,-3.4,4.6,5,9.5,-3.4
The area of the triangle is 33.6
code:
x1, y1, x2, y2, x3, y3 = eval(input("Enter three points for a triangle:"))
side1 = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
side2 = ((x3 - x1) ** 2 + (y3 - y1) ** 2) ** 0.5
side3 = ((x2 - x3) ** 2 + (y2 - y3) ** 2) ** 0.5
s = (side1 + side2 + side3) / 2
area = (s * (s - side1) * (s - side2) * (s - side3)) ** 0.5
print("The area of the triangle is %.1f" % area)

Execution results:

5,   Title: (geometry: area of regular hexagon) write a program to prompt the user to enter the side length of regular hexagon and display its area.

Formula:
Area = (3*(3**0.5)*(s*s))/2 
Implementation objectives:
 Enter the side: 5.5
 The area of the hexagon is 78.5895
code:
side = float(input("Enter the side: "))
area = (3 * (3 ** 0.5) * (side * side)) / 2
print("The area of the hexagon is %.4f" % area)

Execution results:

Topics: Python Algorithm linear algebra