Discuss / Python / 请教下这个语句怎么才能在输入8后结束循环

请教下这个语句怎么才能在输入8后结束循环

Topic source

qs阿怪

#1 Created at ... [Delete] [Delete and Lock User]

print('猜我想的数字') a=input('请输入') a=True while a!=8: a=input('请输入') else: print('结束') 初学python,请教下这个语句怎么才能在输入8后结束循环。

廖雪峰

#2 Created at ... [Delete] [Delete and Lock User]

你的输入是str,用'8'试试

在此插入代码

猜数字,我的数字是8

print('猜数字') while True: a=input('输入数字:') if a == '8': break print('恭喜你猜对了,数字是8')

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

print('猜我想的数字')
a=int(input('请输入'))
while a!=8:
    a=int(input('请输入'))
print('猜对了!')

厉害了


  • 1

Reply