程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Write a simple robot in Python, super simple!

編輯:Python
In this issue, we introduce how to use Python To realize the communication and dialogue between users and machines
Project introduction : Let the user enter the name , Age , weight , Finally, the machine will output some conversational words
Related to knowledge : loop , Conditional statements , Application of string
# -*- coding : utf-8 -*-
# @Time : 2020/8/8
# @author :  Wang Xiaowang
# @Software : PyCharm
# @CSDN : https://blog.csdn.net/weixin_47723732

i=0
name = None
while name != 'Q':
 i = i + 1
 print('***** cycles ', i,"******")

 name = input(" Please enter your name ")
 age = input(" Please enter your age ")
 age = int(age)
 if age >= 0 and age < 100:
 print(&quot; This is the exact age &quot;)
 elif age > 100 or age < 0:
 print(&quot; Sorry, your input is suspicious , Please check &quot;)
 else:
 print(&quot; Your input is wrong &quot;)
 weight = input(&quot; Last question : Please enter your weight number &quot;)
 weight = int(weight)
 a = name.lower()
 print(&quot; Your name is in lowercase :&quot;, a)
 #  perhaps :print(&quot; Your name is in lowercase :&quot;,name.lower())
 b = name.upper()
 print(&quot; Your name is capitalized as :&quot;, b)
 #  perhaps :print(&quot; Your name is capitalized as :&quot;,name.upper())
 #  Additional features :
 print(&quot; Print your name in uppercase :&quot;, name.title())
 print(&quot; Output the length of your name :&quot;, len(name))
 print(&quot; Output the last three letters of the name :&quot;, name[-3:])
 print(&quot; You know, w How many times does your name appear :&quot;, name.count('w'))
 print(&quot; If I use Z representative W What will be output :&quot;, name.replace('w', 'z'))
 print(&quot; Congratulations {} The students are {} Three good students at the age of !&quot;.format(name, age))
 called = name * 5
 print(&quot; If I call you 5 Time , Then it will be :\n&quot;, called)
 life = age * 360 * 24 * 60 * 60
 print(&quot;{} Do you know how many seconds you live ?\n The answer is :&quot;.format(name), life, ' second ')
 moon_weight = weight / 6
 print(&quot;{} The weight on the moon is :&quot;.format(name), moon_weight, ' kg ')
 sun_weight = weight * 27.1
 print(&quot;{} The weight on the sun is :&quot;.format(name), sun_weight, ' kg ')
 # name = input(&quot; Please enter your name again &quot;)
 # age = input(&quot; Please enter your age &quot;)
print(&quot; The program has exited &quot;)


Know how to implement these things , We can define many interesting sentences by ourselves , I'll just briefly introduce it here !
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved