习题2.1-2.8.md

print("Program 'Game Over.'")

print("Same","message","as before.")

print("Just",
      "a bit",
      "bigger.")

print("Here",end=" ")
print("it is ...")

print("""
       GAME
       
       OVER
       
       !!!!

""")
input("\n\nPress the enter key to exit.")
Program 'Game Over.'
Same message as before.
Just a bit bigger.
Here it is ...

       GAME
       
       OVER
       
       !!!!




Press the enter key to exit.3





'3'
#转义字符

print("\t\t\tFancy Credits")

print("\t\t\t \\ \\ \\ \\ \\ \\ \\ \\")
print("\t\t\t\tby")
print("\t\t\tMichael Dawson")
print("\t\t\t \\ \\ \\ \\ \\ \\ \\ \\")

print("\nSpecial thanks goes out to:")
print("My hair stylist,Henry \'The Great,\'who never says \"can\'t.\"")

print("\a")
			Fancy Credits
			 \ \ \ \ \ \ \ \
				by
			Michael Dawson
			 \ \ \ \ \ \ \ \

Special thanks goes out to:
My hair stylist,Henry 'The Great,'who never says "can't."

# 字符串的链接和重复
print("You can concatenate two " + "string with the '+' operator.")
print("\nThis string " + "may not " + "seem terr" + "ibly impressive."\
       + "But what " + "you don't now " + "is that\n" + "it's one real"\
       + "l" + "y " + "long string,created from the concatenation "\
       + "of " + "twenty-two\n" + "different strings,broken across "\
       + "six line." + "Now are you " + "impressed?" + "Okay,\n"\
       + "this " + "one " + "long " + "string is now over!")

print("\nIf you really like a string,you can repeat it.For example,")
print("who doesn't like pie? That's right,nobody.But if you really")
print("like it,you should say it like you mean it:")
print("pie "*10)
You can concatenate two string with the '+' operator.

This string may not seem terribly impressive.But what you don't now is that
it's one really long string,created from the concatenation of twenty-two
different strings,broken across six line.Now are you impressed?Okay,
this one long string is now over!

If you really like a string,you can repeat it.For example,
who doesn't like pie? That's right,nobody.But if you really
like it,you should say it like you mean it:
pie pie pie pie pie pie pie pie pie pie 
#演示数字与数学运算
print("If a 2000 pound pregnant hippo gives bireh to a 100pound calf")
print("but then eats 50 pounds of food,how much does she weigh?")
input("Press the enter key to find out.")
print("2000 - 100 + 50 =",2000-100+50)

print("\nIf an adventurer returns from a successful quest and buys each of")
print("6 companions 3 of a ale,how many bottles are purchased?")
input("Press the enter key to find out.")
print("6*3=",6*3)

print("\nIf a restaurant check comes to 19 dollars with tip,and you and")
print("your friends split it evenly 4 ways,how much do you each throw in?")
input("Press the enter key to find out.")
print("19/4=",19/4)

print("\nIf a group of 4 pirates finds a chest full of 107 gold coins,and")
print("they divide the booty evenly,how many whole coins does each get?")
input("Press the enter key to find out.")
print("107//4=",107//4)

print("\nIf that same group of 4 pirates evenly divides the chest full")
print("of 107 gold coins,how many coins are left over?")
input("Press the enter key to find out.")
print("107%4 = ",107%4)


If a 2000 pound pregnant hippo gives bireh to a 100pound calf
but then eats 50 pounds of food,how much does she weigh?
Press the enter key to find out.
2000 - 100 + 50 = 1950

If an adventurer returns from a successful quest and buys each of
6 companions 3 of a ale,how many bottles are purchased?
Press the enter key to find out.
6*3= 18

If a restaurant check comes to 19 dollars with tip,and you and
your friends split it evenly 4 ways,how much do you each throw in?
Press the enter key to find out.
19/4= 4.75

If a group of 4 pirates finds a chest full of 107 gold coins,and
they divide the booty evenly,how many whole coins does each get?
Press the enter key to find out.
107//4= 26

If that same group of 4 pirates evenly divides the chest full
of 107 gold coins,how many coins are left over?
Press the enter key to find out.
107%4 =  3
#变量的使用
name = "Larry"

print(name)

print("Hi",name)

Larry
Hi Larry
#获取用户输入
name = input("Hi,What's your name?")

print(name)

print("Hi,",name)
Hi,What's your name?lzq
lzq
Hi, lzq
#字符串的使用
quote = "I think there is a world market for maybe five computers."

print("Original quote:",quote)

print("\nIn uppercase:",quote.upper())

print("\nIn lowercase:",quote.lower())

print("\nAs a title:",quote.title())

print("\nWith a minor replacement:",quote.replace("five","millons of"))

print("\nOriginal quote is still:",quote)

# 所有字符串方法只是创建新的字符串,而不会影响原先字符串
Original quote: I think there is a world market for maybe five computers.

In uppercase: I THINK THERE IS A WORLD MARKET FOR MAYBE FIVE COMPUTERS.

In lowercase: i think there is a world market for maybe five computers.

As a title: I Think There Is A World Market For Maybe Five Computers.

With a minor replacement: I think there is a world market for maybe millons of computers.

Original quote is still: I think there is a world market for maybe five computers.

猜你喜欢

转载自blog.csdn.net/DMU_lzq1996/article/details/82937754
2.8