Python从入门到实践编程题答案(第二章)

2-3 :将用户的姓名存到一个变量中,并向该用户显示一条消息。显示的消息应非常简单,如“Hello Eric, would you liketo learn some Python today?”。

name="Eric"
print("Hello "+name+"!Would you like to learn some python today?")

2-4

name_1="john"
print(name_1.title())
print(name_1.upper())
print(name_1.lower())

2-5

name_2="Albert Einstein"
print(name_2 + " once said,\"A person who never madea mistake never\
 tried anything new.\"")

2-6

famous_person="Albert Einstein"
message=famous_person+"once said,\"A person who never madea mistake \
never tried anything new.\""
print(message)

2-7

name_lan="  Cer\tse\ni  "
print(name_lan)
print(name_lan.lstrip())
print(name_lan.rstrip())
print(name_lan.strip())

2-8

print(2+6)
print(10-2)
print(2*4)
print(16/2)

2-9

myFavortNumber=4
message="My favourite number is "+str(myFavortNumber) +"."
print(message)

2-10

#快速打印星星的程序

i=input("你信打印几个星星")
i=int(i)
while i:
    print("*")
    i-=1

你可能感兴趣的:(笔记)