PYTHON编程导论群问题汇总(三)

Q1: week2-3, Ex-guess my number在做week2练习:guess my number时遇到一个小问题。代码已经写好,结果也和给出的答案一样,但是格式有一点不同,如下:# 这是我的outputPlease think of a number between 0 and 100!Is your secret number 50?Enter 'h' t...
摘要由CSDN通过智能技术生成

Q1: week2-3, Ex-guess my number

在做week2练习:guess my number时遇到一个小问题。
代码已经写好,结果也和给出的答案一样,但是格式有一点不同,如下:
# 这是我的output
Please think of a number between 0 and 100!
Is your secret number 50?
Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.
l
# 这是答案expected output
Please think of a number between 0 and 100!
Is your secret number 50?
Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly. l

可以发现区别在于答案的输入l是在“Enter ‘h’ to indicate the guess is too high. Enter ‘l’ to indicate the guess is too low. Enter ‘c’ to indicate I guessed correctly.”的同一行,而我的有一个换行,调整了半天也不知道如何让他们处于同一行,故请教大大们。我的代码如下,比较丑陋…

i = 50
low = 0
high = 99
print('Please think of a number between 0 and 100!')
print('Is your secret number: 50?')
while True: 
    print("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.")
    a = input() # 问题出在这里,如何能将input和上面的print内容显示在一行里
    if a != 'h' or 'l' or 'c':
        print('Sorry, I did not understand your input.')
        print('Is your secret number:' + str(i) + '?')
        print("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.")
        a = input()
    elif a == 'l':
        low = i
        i = int((i+high)/2)
        print('Is your secret number:' + str(i))
    elif
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值