Python 6版本如何实现接收用户输入功能?

2026-05-21 20:182阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计491个文字,预计阅读时间需要2分钟。

Python 6版本如何实现接收用户输入功能?

首先,这是一个简单的Python程序,用于询问用户的年龄、身高和体重。下面是简化后的版本,不超过100个字:

python输入个人信息print(How old are you?, end= )age=input()print(How tall are you?, end= )height=input()print(How much do you weigh?, end= )weight=input()

先来第一个版本:

exercise 11 Asking Question

print("How old are you?",end=" ")
age = input()

print("How tall are you?",end=" ")
height = input()

print("How much do you weight?",end=" ")
weight = input()

print(f"So, you're {age} old,{height} tall and {weight} heavy.")

input函数会接收用户输入,程序里需要把参数保存到变量,否则就没有意义.

exercise 12 Prompting People

age=input("你多大了? ")
height=input("小哥哥今年多高? ")
weight = input("你体重多少? ")

print(f"好了,我现在知道你的年龄是{age}岁,身高是{height}cm,体重是{weight}公斤.")

这样写起来更加清爽,简便,input里面是提示语,终端输入是值.

Python 6版本如何实现接收用户输入功能?

查看模块帮助,-m参数表示引用的模块,例如下面,我们引用帮助文档模块,插卡input的使用说明.

再来看一个:

exercise 13 parameters upacking variables

from sys import argv

# read the WYSS section for how to run this
script,first,second,third = argv

print("The script is called:",script)
print("Your first variable is:",first)
print("Ypur secod variable is:",second)
print("Your third variable is:",third)

一次獲取多個參數,並把參數分配給相應的變量.

exercise 14 Prompting and Passing

from sys import argv

script, user_name = argv
prompt = '> '

print(f"Hi {user_name}, I'm the {script} script.")
print(f"I'd like to ask you a few questions.")
print(f"Do you like me {user_name}?")

likes = input(prompt)

print(f"Where do you like live {user_name}?")
lives = input(prompt)

print(f"What kind of compture do you have?")
compture = input(prompt)

print(f"""
Alright, so you said {likes} about liking me.
You live in {lives}. Not sure where that is.
And you have a {compture} compture.Nice.
""")


本文共计491个文字,预计阅读时间需要2分钟。

Python 6版本如何实现接收用户输入功能?

首先,这是一个简单的Python程序,用于询问用户的年龄、身高和体重。下面是简化后的版本,不超过100个字:

python输入个人信息print(How old are you?, end= )age=input()print(How tall are you?, end= )height=input()print(How much do you weigh?, end= )weight=input()

先来第一个版本:

exercise 11 Asking Question

print("How old are you?",end=" ")
age = input()

print("How tall are you?",end=" ")
height = input()

print("How much do you weight?",end=" ")
weight = input()

print(f"So, you're {age} old,{height} tall and {weight} heavy.")

input函数会接收用户输入,程序里需要把参数保存到变量,否则就没有意义.

exercise 12 Prompting People

age=input("你多大了? ")
height=input("小哥哥今年多高? ")
weight = input("你体重多少? ")

print(f"好了,我现在知道你的年龄是{age}岁,身高是{height}cm,体重是{weight}公斤.")

这样写起来更加清爽,简便,input里面是提示语,终端输入是值.

Python 6版本如何实现接收用户输入功能?

查看模块帮助,-m参数表示引用的模块,例如下面,我们引用帮助文档模块,插卡input的使用说明.

再来看一个:

exercise 13 parameters upacking variables

from sys import argv

# read the WYSS section for how to run this
script,first,second,third = argv

print("The script is called:",script)
print("Your first variable is:",first)
print("Ypur secod variable is:",second)
print("Your third variable is:",third)

一次獲取多個參數,並把參數分配給相應的變量.

exercise 14 Prompting and Passing

from sys import argv

script, user_name = argv
prompt = '> '

print(f"Hi {user_name}, I'm the {script} script.")
print(f"I'd like to ask you a few questions.")
print(f"Do you like me {user_name}?")

likes = input(prompt)

print(f"Where do you like live {user_name}?")
lives = input(prompt)

print(f"What kind of compture do you have?")
compture = input(prompt)

print(f"""
Alright, so you said {likes} about liking me.
You live in {lives}. Not sure where that is.
And you have a {compture} compture.Nice.
""")