python-6.接受用户输入(python用于获取用户输入的命令)

网友投稿 346 2022-08-26


python-6.接受用户输入(python用于获取用户输入的命令)

先来第一个版本:

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}公斤.")

exercise 13 parameters upacking variables

from sys import argv# read the WYSS section for how to run this script,first,second,third = argvprint("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 argvscript, user_name = argvprompt = '> '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.""")


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:python-5.原样输出,转义字符(python中转义字符用法及例子)
下一篇:python多线程爬取网页名称写入到excel
相关文章

 发表评论

暂时没有评论,来抢沙发吧~