zoukankan      html  css  js  c++  java
  • Python学习的第二天

    格式化:

    name=input("Name")
    job=input("Job")
    age=input("Age")
    hometown=input("hometown")
    info=""
    ------------info of %s --------------
    Name: %s
    Age: %s
    Job: %s
    Hometown:%s
    ------------End -------------------
    ""%(name,name,age,job,hometown)

    print(info)

    #s=string
    #d=digit
    #f=float

    流程分支:

    score=int(input("score"))
    if score >100
    print("分数值不能超过100分")
    elif score >=90
    print("A")
    elif score >=80
    print("B")
    elif score >=70
    print("C")
    elif score >=60
    print("D")
    elif score >=0
    print("E")
    else
    print("分数不能低于零")

    age=26
    user_guess=int(input("your guess"))
    if user_guess==age
    print("猜对啦")
    elif user_guess> age
    print("数据猜大了")
    else
    print("数据猜小了")

    While 循环语句

    让程序从0打印到100的程序,每循环一次
    count=0
    while count<=100
    print("loop",count)
    count +=1

    print("--loop is end--")

    打印偶数
    count=0
    while count<=100
    if count%2==0
    print("loop",count)
    count +=1

    print("--loop is end--")

    第50次不打印,第60-80打印对应值的平方

    自己
    count=0
    while count<=100
    if count!=50 and count<60 and count<80
    print("loop",count)
    else
    print("loop",count*count)
    count +=1

    print("--loop is end--")

    老师
    count=0
    while count<=100
    if count==50
    pass
    elif count>=60 and count<=80
    print("loop",count*count)
    else
    print("loop",count)
    count +=1


    死循环
    count=0
    while True:
    print("您",count)
    count +=1

    循环终止语句break 或者continue
    break 完全跳出所有循环
    continue
    count =0
    while count<=100
    print("loop",count)
    if count==5
    break
    count +=1
    print("---out of the loop---")
    跳出,中止

    count =0
    while count<=100
    print("loop",count)
    if count==5
    continue
    count +=1
    print("---out of the loop---")

    后面一直55555.

    打印1-5,95-100
    count =0
    while count<=100
    count +=1
    if count>5 and count<95
    continue
    print("loop",count)
    作业:
    age=26
    count=1
    while count<=3
    age_guess=input("age_guess")
    if age_guess=age
    break
    else
    count+=1

    print"----game over----"

    age=26
    count=1
    answer="Y"
    answer_=input("YorN")
    if answer_=answer
    count=1
    while count<=3
    age_guess=input("age_guess")
    if age_guess=age
    break
    else
    count+=1
    answer_=input("YorN")
    else
    print"----game over----"

  • 相关阅读:
    Java微信二次开发(八)
    Java微信二次开发(七)
    Java微信二次开发(六)
    Java微信二次开发(五)
    Java微信二次开发(四)
    Java微信二次开发(三)
    IIS中X509Certificate遇见的问题
    SQL Server 数据库定时自动备份
    ASP.NET 5 (vNext) 理解和概述
    ASP.NET 5 (vNext) Linux部署
  • 原文地址:https://www.cnblogs.com/rainbowupdate/p/10828578.html
Copyright © 2011-2022 走看看