设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
楼主: crossin先生
打印 上一主题 下一主题

【Python 第14课】 字符串格式化

[复制链接]

0

主题

0

好友

70

积分

注册会员

Rank: 2

11#
发表于 2016-8-28 20:45:12 |只看该作者
我看那位地板上的朋友有两行用elif来代替if,但是实际上对结果也没什么影响,elif和if有什么区别?
回复

使用道具 举报

174

主题

45

好友

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

12#
发表于 2016-8-29 10:54:12 |只看该作者
十三才 发表于 2016-8-28 20:45
我看那位地板上的朋友有两行用elif来代替if,但是实际上对结果也没什么影响,elif和if有什么区别? ...

看这里:
【Python 第23课】 if, elif, else
http://bbs.crossincode.com/forum ... d=909&fromuid=3
#==== Crossin的编程教室 ====#
微信ID:crossincode
网站:http://crossincode.com
回复

使用道具 举报

0

主题

0

好友

70

积分

注册会员

Rank: 2

13#
发表于 2016-8-29 10:56:29 |只看该作者
crossin先生 发表于 2016-8-29 10:54
看这里:
【Python 第23课】 if, elif, else
http://bbs.crossincode.com/forum.php?mod=viewthread&tid= ...

后面会讲到啊,我一点一点来吧
回复

使用道具 举报

0

主题

0

好友

8

积分

新手上路

Rank: 1

14#
发表于 2016-11-25 16:14:24 |只看该作者
感谢!!!
回复

使用道具 举报

0

主题

0

好友

96

积分

注册会员

Rank: 2

15#
发表于 2016-12-4 18:22:33 |只看该作者
from random import randint
num = randint(1,100)
print'guess waht i think?'
bingo = False
while bingo == False:
    answer = input()

    if answer < num:
        print'%d is too small'%answer
    if answer > num:
        print'%d is too big'%answer
    if answer == num:
        print'%d is bingo'%answer
        bingo = True
回复

使用道具 举报

0

主题

0

好友

6

积分

新手上路

Rank: 1

16#
发表于 2016-12-12 16:00:13 |只看该作者
from random import randint
num=randint(0,101)
print'''Guess what No. I'm thinking'''
answer=101
while answer!=num:
    answer=input()
    if answer>num:
        print str(answer)+' is too big'
    if answer<num:
        print str(answer)+' is too small'
    if answer==num:
        print 'BINGO '+str(answer)+' is right the number I was thinking!'
回复

使用道具 举报

0

主题

0

好友

34

积分

新手上路

Rank: 1

17#
发表于 2016-12-19 21:05:07 |只看该作者
from random import randint
num1=randint(1,50)

print 'guess what num i\'m thinking?'
bingo=False
while bingo==False:
    x=input()
    if x>num1:
        print str(x)+' is too big'
    if x<num1:
        print str(x)+' is too small'
    if x==num1:
        print str(x)+' is the right answer'
        bingo=True


num2=randint(1,50)
aa='Your answer '

print 'guess another num?'
bingo=False
while bingo==False:
    y=input()
    if y>num2:
        print '%s'%aa+str(y)+' is too big'
    if y<num2:
        print '%s'%aa+str(y)+' is too small'
    if y==num2:
        print '%s'%aa+str(y)+' is right'
        bingo=True
回复

使用道具 举报

0

主题

0

好友

34

积分

新手上路

Rank: 1

18#
发表于 2016-12-19 21:07:32 |只看该作者
求点评!
回复

使用道具 举报

174

主题

45

好友

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

19#
发表于 2016-12-20 14:06:45 |只看该作者
ponber 发表于 2016-12-19 21:05
from random import randint
num1=randint(1,50)

可以的。
你可以再尝试用while循环,把它写成一个可以一直猜的程序
#==== Crossin的编程教室 ====#
微信ID:crossincode
网站:http://crossincode.com
回复

使用道具 举报

0

主题

0

好友

34

积分

新手上路

Rank: 1

20#
发表于 2016-12-20 19:33:44 |只看该作者
from random import randint
m=0
while m==0:
    num=randint(1,50)
    bingo=False
    aa='Your answer '
    print'Just guess and guess again,don\'t stop!\nDo what \
Mr Crossin told you to do,please!'
    while bingo==False:
        x=input()
        if x<num:
            print'%s'%aa+str(x)+' is small'
        if x>num:
            print'%s'%aa+str(x)+' is big'
        if x==num:
            print'%s'%aa+str(x)+' is bingo'
            bingo=True
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-4-20 00:34 , Processed in 0.030491 second(s), 21 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部