1. 程式人生 > 其它 >學習python第n天——我在看笨辦法學python(這是所有的輸入和輸出了)

學習python第n天——我在看笨辦法學python(這是所有的輸入和輸出了)

這是所有的語言

print ("Hello world!")
print ("Hello again")
print ("I like typing this.")
print ("This is fun.")
print ("Yay!Printing.")
print ("I'd much rather you 'not'.")
print ('I "said" do not touch this.')
# Anything after the # is ingnord by python.octothorpe.

print ("now I will count my chickens.")

print ("Hens",20+30/6)
print ("Roosters",100-25*3%5)

print ("now I will count my eggs.")

print (3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6)

print ("IS it ture that 3 + 2 < 5 - 7 ?")

print (3 + 2 < 5 - 7)
print ("oh,that's why it's false.")

print ("what is 3 + 2?", 3 + 2)
print ("what is 5 - 7?", 5 - 7)

cars = 100
space_in_a_car = 4.0
drivers = 30
passengers = 90
#定義了四個物件,並賦值

cars_not_driven = cars - drivers
cars_driven = drivers
carpool_capacity = cars_driven * space_in_a_car
average_passengers_per_car = passengers / cars_driven
#一些計算過程

print ( cars )
print ( drivers )
print ( average_passengers_per_car )
#一些輸出

my_name = 'Zed A. Shaw'
my_age = 35# not a lie

my_Height = 163#CM
cm_feet = ( my_Height ) / 30.48
print ( cm_feet )#這是一些實驗

my_weight = 53#KG
kg_pound = 0.4535923 * ( my_weight )
print ( kg_pound )#這是一些實驗

my_eyes = 'black'
my_hair = 'black'#我是中國人,這是一些輸入

print (f"Let's talk about {my_name}.")
#不要忘記f
print (f"He is {my_age} years old.")
print (f"He is {my_weight} kg heavy.")
print (f"He is {kg_pound} pound heavy.")
print ("He is {} pound heavy.".format(kg_pound))#這是一個實驗(他成功了)
print (f"Actually , it's not too heavy.")
#以上基於實際資料

types_of_people = 10
x = f"There are {types_of_people} types of people."

binary = " binary "
do_not = " don't "
y = f" Those who know {binary} and those who {do_not}."

print ( x )
print ( y )

print (f"I said :{ x }")
print (f"I also said :'{ y }'")

hilarious = False
#應該是固定格式,F大寫
joke_evaluation = "Isn't the joke so funny? {}!"
#應該是使用了format函式,我承認我不大瞭解

print (joke_evaluation.format(hilarious))

w = "This is the left side of..."
e = "a string with a right side."

print ( w + e )

print ("Mary had a little lamb.")
print ("It's fleece was wite as {}.".format('snow'))
print ("And everywhere that Mary went.")
print ("." * 10)
#what'd that do?

end1 = "C"
end2 = "h"
end3 = "e"
end4 = "e"
end5 = "s"
end6 = "e"

end7 = "B"
end8 = "u"
end9 = "r"
end10 = "g"
end11 = "e"
end12 = "r"

print (end1 + end2 + end3 + end4 + end5 + end6, end = ' ')#另外一種輸入,可以輸入空格
print (end7 + end8 + end9 + end10 + end11 + end12 )

formatter = "{} {} {} {} "#這是一個定義字串的過程,是一個固定搭配

print(formatter.format(1, 2, 3, 4))
print(formatter.format("one", "two", "three", "four"))
print(formatter.format(True, False, True, False))
print(formatter.format(formatter,formatter, formatter,formatter))
print(formatter.format(
"Try your",
"Own text here",
"Maybe a poem",
"Or a song about fear"
))#formatter.format()是一個給字串賦值的過程

# Here's some new strange stuff, remember type it exactly.

days = "Mon Tue Wed Thu Fri Sat Sun"
months = "\nJan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"
#換行字元(new line character)
#三個雙引號是用來換行的

print("Here are the days: ", days)
print("Here are the months: ", months)

print("""
There's something going on here.
With the three double-quotes.
We will be able to type as much as we like.
Even 4 lines if we whant , or 5, or 6.
""")
#三個雙引號也是用來換行的,也可以用'''

tabby_cat = "\tI'm tabbed in."
persian_cat = "I'm split\non a line."
backslash_cat = "I'm \\a\\cat."

fat_cat = """
I'll do a list:
\t* cat food
\t* Fishies
\t* Catnip\n\t* Grass
"""
#轉義字元(escape sequence)

print(tabby_cat)
print(persian_cat)
print(backslash_cat)
print(fat_cat)
#以上都是輸出的內容,下面會做一些輸入

print("How old are you?", end=' ')
age = input()

print("How tall are you?", end=' ')
print("要記得單位是cm哦!")
print("這裡只能輸入一個小數。")
height = int(float(input()))#這裡輸入的是一個小數,可以加一個if語句。

print("How much do you weight?", end=' ')
print("要記得單位是kg哦!")
print("這裡只能輸入一個小數。")
weight = int(float(input()))
#int()給輸入的數字取整。float表示輸入的是一個小數。

print(f"So,you are {age} years old, {height} cm tall and {weight} kg heavy.")

#下面是另一種寫法。
age1 = input("How old are you?")
height1 = int(float(input("\nHow tall are you?\n要記得單位是cm哦!\n這裡只能輸入一個小數。")))
weight1 = int(float(input("\nHow much do you weight?\n要記得單位是kg哦!\n這裡只能輸入一個小數。")))
print(f"So,you are {age1} years old, {height1} cm tall and {weight1} kg heavy.")
# python -m pydoc -w ex1這個可以輸出一個exe檔案,和一個html檔案(可以按A-Z整理出所有的變數)

這是所有的執行結果

PS C:\Users\HH\lpthw> python ex1.py
Hello world!
Hello again
I like typing this.
This is fun.
Yay!Printing.
I'd much rather you 'not'.
I "said" do not touch this.
now I will count my chickens.
Hens 25.0
Roosters 100
now I will count my eggs.
6.75
IS it ture that 3 + 2 < 5 - 7 ?
False
oh,that's why it's false.
what is 3 + 2? 5
what is 5 - 7? -2
100
30
3.0
5.347769028871391
24.0403919
Let's talk about Zed A. Shaw.
He is 35 years old.
He is 53 kg heavy.
He is 24.0403919 pound heavy.
He is 24.0403919 pound heavy.
Actually , it's not too heavy.
There are 10 types of people.
Those who know binary and those who don't .
I said :There are 10 types of people.
I also said :' Those who know binary and those who don't .'
Isn't the joke so funny? False!
This is the left side of...a string with a right side.
Mary had a little lamb.
It's fleece was wite as snow.
And everywhere that Mary went.
..........
Cheese Burger
1 2 3 4
one two three four
True False True False
{} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}
Try your Own text here Maybe a poem Or a song about fear
Here are the days: Mon Tue Wed Thu Fri Sat Sun
Here are the months:
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug

There's something going on here.
With the three double-quotes.
We will be able to type as much as we like.
Even 4 lines if we whant , or 5, or 6.

I'm tabbed in.
I'm split
on a line.
I'm \a\cat.

I'll do a list:
* cat food
* Fishies
* Catnip
* Grass

How old are you? 21
How tall are you? 要記得單位是cm哦!
這裡只能輸入一個小數。
163.3
How much do you weight? 要記得單位是kg哦!
這裡只能輸入一個小數。
53.3
So,you are 21 years old, 163 cm tall and 53 kg heavy.
How old are you?21

How tall are you?
要記得單位是cm哦!
這裡只能輸入一個小數。163.7

How much do you weight?
要記得單位是kg哦!
這裡只能輸入一個小數。53.7
So,you are 21 years old, 163 cm tall and 53 kg heavy.
PS C:\Users\HH\lpthw>