Day2_Udemy Python 100days

#data types and type checking

    #type conversion
num_char=len(input("What is your name?"))
print("Your name has "+num_char+" charaters")
TypeError: can only concatenate str (not "int") to str

num_char=len(input("What is your name?"))
new_num_char=str(num_char)
print("Your name has "+new_num_char+" charaters")


    #type checking
a=str(123)
print(type(a))

print(70+float("100.5"))
print(str(70)+str(100))

    #2.1
two_digit_number=input("Type a two digit number:")
print(type(two_digit_number))
first_number=int(two_digit_number[0])
second_number=int(two_digit_number[1])
result=first_number+second_number
print(result)


    #mathematical operations
#PEMDAS(from left to right)
#()  bracket or parentheses
# **  exponents
# * / multiplication division
# + - addition subtraction

    #2.2 BMI calculator
height=float(input("enter your height in m:"))
weight=int(input("enter your weight in kg:"))
print(type(height))
bmi=weight/height**2
bmi_as_int=int(bmi)
print(bmi_as_int)


    #round numbers
#print(round(8/3))   3
#print(round(8/3,2)) 2.67
#print(8//3)         2
#print(type(8/3))    float
#print(type(8//3))   int
#result=4/2
#result/=2      #+=  *=  -=
#print(result)

    #f-String
#所有不同的数据类型通过使用f组合成一个字符串,使用花括号来放置变量
score=0
height=1.8
isWinning=True
print(f"your score is {score},your height is {height},you are winning is {isWinning}")


    #2.3 Your Life in Weeks
age = input ("What is your current age?")
age_as_int=int(age)
years_remaining=90-age_as_int
days_remaining=years_remaining*365
weeks_remaining=years_remaining*52
months_remaining=years_remaining*12
message=f"You have {days_remaining} days,{weeks_remaining} weeks,and {months_remaining} months left."
print(message)


    #Project_Tip Calculator
print("Welcome to the tip calculator.")
bill=float(input("What was the total bill?$"))
tip=int(input("What percentage tip would you like to give?10,12or15?"))
person=int(input("How many people to spilt the bill?"))
total_bill=bill*(1+tip/100)
bill_per_person=total_bill/person
#final_amount=round(bill_per_person,2)
final_amount="{:.2f}".format(bill_per_person)
#格式化:把一个浮点数变成了一个字符串,并且该字符串遵循这种特殊格式,即两位小数
print(f"Each person should par:${final_amount}")

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值