Day01_ after-school exercises

1. (Fahrenheit to Celsius conversion) write a reading Celsius and Fahrenheit him into the program and be displayed from the console. Conversion formula is as follows.

F = (9/5) * celsius + 32

Here is an example of running the program.

Enter a degree in Celsius:43
43 Celsius is 109.4 Fahrenheit
代码:

celsius = float(input('Enter a degree in Celsius:'))
fahrenheit = (9.0 / 5.0) * celsius + 32
print(' %.0f Celsius is %.1f Fahrenheit '%(celsius,fahrenheit))

operation result:

2. (calculated volume of the cylinder) to prepare a radius of the cylinder and a high reading and using the following formula to calculate the area and volume of the cylinder bottom procedures:

area = radius * radius * pi

volume = area * length

Running instance:

Run the code:

import math
radius,length = eval(input('Enter the radius and length of a cylinder:'))
area = radius ** 2 * math.pi
volume = area * length
print('The area is %.4f'%area)
print('The volume is %.1f'%volume)

operation result:

3 (the number of feet is converted to meters) to write a program that reads the number of feet and he converted into a display and a few meters. One foot is equal to 0.305 meters.

 Run the code:

feet = float(input('Enter a value for feet:'))
meter = feet * 0.305
print('%.1f feet is %.4f meters'%(feet,meter))

operation result:

4. (to calculate the energy) to write a program that calculates the water is heated from an initial temperature to a final temperature of the energy required. Enter the calculated weight of water and the initial temperature and final temperature of one kilogram. Formula: Q = M * (finaltem - inittem) * 4184

Run the code:

kilograms = float(input('Enter the amount of water kilograms:'))
inittem = float(input('Enter the initial temperature:'))
finaltem = float(input('Enter the final temperature:'))
Q = kilograms * (finaltem - inittem) * 4184
print('The energy needed is %.1f'%Q)

operation result:

5. Calculate the interest, and if you know the difference between the percentage of the annual interest rate, the interest may be calculated monthly for the next month using the following formula.

                 * = Difference interest (APR / 1200)

The difference between reading and writing programs APR, interest calculation.

Run the code:

balance,rate = eval(input('Enter balance and interest rate (e.g.,3 for 3%):'))
interest = balance * (rate / 1200)
print('The interest is %.5f'%interest)

运行结果:

6.计算平均加速度

运行代码:

v0,v1,t = eval(input('Enter v0,v1 and t:'))
a = (v1-v0) / t
print('The average acceleration is %.4f'%a)

运行结果:

7. 

代码:

amount = input('Enter the monthly saving amount:')
sum = 0
for i in range(6):
    sum = (sum+float(amount)) * (1 + 0.00417)
print('After the sixth month,the account value is %.2f'%sum)

运行结果:

8.

运行代码:

num = int(input("Enter a number between 0 and 1000:"))
if num < 0 and num > 1000:
    print('输入有误')
else:
    a = int(num % 100)
    b = a % 10 # 百位数
    c = int(a / 10) # 十位数
    d = int(num / 100) # 个位数
    sum = b + c + d
print('The sum of the digits is %d'%sum)

运行结果:

 

 

 

 

 

 

 

 

 



Guess you like

Origin www.cnblogs.com/KAJIA1/p/11272137.html