Home > Backend Development > Python Tutorial > Python learning with Guibs_While&Input

Python learning with Guibs_While&Input

黄舟
Release: 2017-01-20 16:14:39
Original
1612 people have browsed it

Guibs’ Python Learning_While&Input

# While And Input# input()# input() 接收一个参数: 即要向用户显示的提示或说明message = input("告诉我你想跟我说的话, 我会重复你的话~\n")
print("你说: " + message)# 使用 int() 来获取数值输入age = input("你多大?\n")
print(&#39;那么. 你明年&#39; + str(int(age) + 1) + &#39;了&#39;)# 使用 while 循环current_number = 1while current_number <= 5:
    print(current_number)
    current_number += 1# 1 2 3 4 5# 使用标志来控制循环activity = Truenum = 1while activity:
    print("Hello")
    num += 1
    if num == 3:
        activity = False# Hello Hello# 使用 break 退出循环current_number = 1while current_number <= 5:    if current_number != 3:
        print(current_number)
        current_number += 1
    else:        break# 1 2# 使用 continue 跳入下一次循环current_number = 1while current_number <= 5:    if current_number != 3:
        print(current_number)
        current_number += 1
    else:
        current_number += 1
        continue# 1 2 4 5# 使用 while 处理列表和字典unconfirmed_users = [&#39;Alice&#39;, &#39;Guibs&#39;, &#39;Mike&#39;]
confirmed_users = []
print("未确认名单: " + str(unconfirmed_users))
print("已确认名单: " + str(confirmed_users))while unconfirmed_users:
    current_user = unconfirmed_users.pop()
    confirmed_users.append(current_user)
    print(current_user + " 已确认")
print("未确认名单: " + str(unconfirmed_users))
print("已确认名单: " + str(confirmed_users))# 删除包含特定值的所有列表元素pets = [&#39;dog&#39;, &#39;cat&#39;, &#39;dog&#39;, &#39;goldfish&#39;, &#39;rabbit&#39;]while &#39;dog&#39; in pets:
    pets.remove(&#39;dog&#39;)
print(pets)# 使用用户输入来填充字典responses = {}
polling_active = Truewhile polling_active:
    name = input("叫什么名字\n")
    response = input("喜欢什么\n")
    responses[name] = response
    repeat = input("是否继续添加?是/否\n")    if repeat == &#39;否&#39;:
        polling_active = Falseprint(responses)
Copy after login

The above is the content of Guibs’ Python Learning_While&Input. For more related content, please pay attention to the PHP Chinese website (www .php.cn)!


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template