我要努力学Python了

我要努力学Python了

看了差不多一个月的Python,看的时候感觉啥都懂,但是,关掉视频就傻逼了,啥也不知道了。
现在开始,要边看教程边写程序了,而且还要写一些博客来记录自己。
以下是我自己照着视频,写的一些代码(PS:有的代码我经过小幅度的修改)
1.hello world(听说是程序员第一个代码基本上都是它)

print("hello world")
print("what is your name?")
myname=input()
print('nice to meet you '+ myname )
print("the length of your name is " +str(len(myname)) )
print("how old are you ?")
myage=input()
print("you will be " + str((int(myage)+1)) +"in a year" )

人民币与美元的汇率换算

dollar = input("Enter dollar : ")
dollar = int(dollar)
CNY = dollar * 6.67 #6.67为汇率,可随意修改的
print("{} dollar equals {} yuan " . format(dollar , CNY))

3.数学基本运算

#输入两个数,并用空格隔开
num1 , num2 = input("Enter 2 numbers: ").split()
#把字符串改成整数型
num1=int(num1)
num2=int(num2)
#把四则运算写入
sum = num1 + num2
diffence = num1 - num2
product = num1 * num2
quotient = num1 / num2
remainder = num1 % num2
#打印出来结果
print(" {} + {} ={} ".format(num1 ,num2 , sum ))
print(" {} - {} ={} ".format(num1 ,num2 , diffence ))
print(" {} * {} ={} ".format(num1 ,num2 , product ))
print(" {} / {} ={} ".format(num1 ,num2 , quotient ))
print(" {} % {} ={} ".format(num1 ,num2 , remainder ))

4.简单的判断语句
(这个代码还可以向其它方向改进)

name = input("请输入名字:")
#如果输入的是suyi
if name == "suyi":
    print("hi suyi ")

if name == "su" :
    print("请确认输入为suyi")
print('done')

5.本金利率计算

# problem : determine grade
#ask for the age and birth month
age, birthmonth = input("enter age and birthmonth :").split()
age = int(age)
birthmonth = int(birthmonth)

if age < 7 or (age ==7 and birthmonth>=9 ) :
    print("too young for school")
elif (age < 13) or (age==13 and birthmonth>=9) :
    if birthmonth >=9:
        grade = age -7
    else:
        grade = age -6
    print(" go to {} grade of primary school" . format(grade))
elif (age < 16) or (age==16 and birthmonth>=9) :
    if birthmonth >=9:
        grade = age -13
    else:
        grade = age -12
    print(" go to {} grade of high school" . format(grade))
elif (age < 19) or (age == 19 and birthmonth >= 9):
    if birthmonth >= 9:
        grade = age - 16
    else:
        grade = age - 15
    print(" go to {} grade of univercity school".format(grade))

6.找1-20的奇数

#找1到20的奇数
for i in range(1,21):
    if ( i % 2) != 0:
        print("i is odd ,i= ", i )

7.problem : determine grade

# problem : determine grade
#ask for the age and birth month
age, birthmonth = input("enter age and birthmonth :").split()
age = int(age)
birthmonth = int(birthmonth)

if age < 7 or (age ==7 and birthmonth>=9 ) :
    print("too young for school")
elif (age < 13) or (age==13 and birthmonth>=9) :
    if birthmonth >=9:
        grade = age -7
    else:
        grade = age -6
    print(" go to {} grade of primary school" . format(grade))
elif (age < 16) or (age==16 and birthmonth>=9) :
    if birthmonth >=9:
        grade = age -13
    else:
        grade = age -12
    print(" go to {} grade of high school" . format(grade))
elif (age < 19) or (age == 19 and birthmonth >= 9):
    if birthmonth >= 9:
        grade = age - 16
    else:
        grade = age - 15
    print(" go to {} grade of univercity school".format(grade))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值