【HW】第二章作业 2018.3.8

Python代码:

#Chapter 2 homework   by szh 2018.3.8
print(2.1)
message = "This is a simple message."
print(message)

print()
print(2.2)
message = "This is also a simple message."
print(message)

print()
print(2.3)
name = "Eric"
print("“Hello " + name + ", would you like to learn some Python today?")

print()
print(2.4)
name = "Albert Einstein"
print(name.title())
print(name.upper())
print(name.lower())

print()
print(2.5)
print('Albert Einstein once said, "A person who never made a mistake never tried anything new."')

print()
print(2.6)
famous_name = name
message = '"A person who never made a mistake never tried anything new."'
print(famous_name + " once said," + message)

print()
print(2.7)
name = "\nAlbert Einstein\t"
print(name.lstrip())
print(name.rstrip())
print(name.strip())

print()
print(2.8)
print(3+5)
print(9-1)
print(2*4)
print(16/2)

print()
print(2.9)
favorite_num = 3;
print("My favorite num is " + str(favorite_num) + ".")

print()
print(2.11)
import this

输出结果:

2.1
This is a simple message.

2.2
This is also a simple message.

2.3
“Hello Eric, would you like to learn some Python today?

2.4
Albert Einstein
ALBERT EINSTEIN
albert einstein

2.5
Albert Einstein once said, "A person who never made a mistake never t

2.6
Albert Einstein once said,"A person who never made a mistake never tr

2.7
Albert Einstein

Albert Einstein
Albert Einstein

2.8
8
8
8
8.0
2.9
My favorite num is 3.

2.11
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

猜你喜欢

转载自blog.csdn.net/empire_03/article/details/79482206