Buffer

# -*- coding: utf-8 -*-
"""
Created on Tue Feb 21 15:20:48 2017

@author: admin
"""

# 2.1(Convert Celsius to Fahrenheit)
celsius = eval(input("Enter a degree in Celsiur: "))

fahrenheit = (9 / 5) * celsius + 32

print(celsius, "Celsius is ", fahrenheit, "Fahrenheit")

# 2.2(Compute the volume of a cylinder)
radius, length = eval(input("Enter the radius and length of a cylinder: "))

PI = 3.14159
area = radius * radius * PI
volume = area * length

print("The area is ", round(area * 10000) / 10000  )
print("The volume is ", round(volume * 10) / 10 )

# 2.3(Convert feet into meters)
feet = eval(input("Enter a value for feet: "))
meters = feet * 0.305
print(feet, " feet is ", meters, "meters")

# 2.4(Convert pounds into kilograms)
pounds = eval(input("Enter a value in pounds:"))
kilograms = pounds * 0.454
print(pounds, " pounds is ", kilograms, "kilograms")

# 2.5(Financial application: calculate tips)
subtotal, gratuityRate = eval(input("Enter the subtotal and a gratuity rate: "))
gratuity = subtotal * gratuityRate / 100
print("The gratuity is ", gratuity, " and the total is ", subtotal + gratuity)

# 2.6(Sum the digits in an integer)
inputNumber = eval(input("Enter a number between 0 and 1000:"))
unitsDigitOfInputNumber = inputNumber % 10
remainingNumber = inputNumber // 10
tensDigitOfInputNumber = remainingNumber % 10
hundredDigitOfInputNumber = remainingNumber // 10

sumTheDigits = unitsDigitOfInputNumber + tensDigitOfInputNumber + hundredDigitOfInputNumber

print("The sum of the digits is ", sumTheDigits)

# 2.7(Find a number of years and days)
minutes = eval(input("Enter the number of minutes: "))
days = int(minutes / 60 / 24)
years = int(days // 365)
remainingdays = int(days % 365)
print(minutes, " minutes is approximately", years, "years and", remainingdays, "days")
 
# 2.8()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值