PY4E exercise chapter2

在参加Coursera课程的时候,老师提供的材料书里的相关代码练习。

  • Exercise 2: Write a program that uses input to prompt a user for their name and then welcomes them.

Enter your name: Chuck
Hello Chuck

name=input('Enter your name:')
print('Hello',name)
  • Exercise 3: Write a program to prompt the user for hours and rate per hour to compute gross pay.

Enter Hours: 35
Enter Rate: 2.75
Pay: 96.25

hours=input('Enter Hours: ')
rate=input('Enter Rate: ')
pay=float(hours)*float(rate)
print('Pay:',pay)
  • Exercise 4: Assume that we execute the following assignment statements:
    width = 17
    height = 12.0
    For each of the following expressions, write the value of the expression and the type (of the value of the expression).
  1. width//2

  2. width/2.0

  3. height/3

  4. 1 + 2 * 5
    作业截图

  • Exercise 5: Write a program which prompts the user for a Celsius temperature, convert the temperature to Fahrenheit, and print out the converted temperature.
Celsius=input('Celsius is: ')
Fahrenheit=float(Celsius)*9/5+32
print('Fahrenheit is= ',Fahrenheit)
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值