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