1. 程式人生 > >Pyhton基礎 day1

Pyhton基礎 day1

格式化輸出 數字 之前 user for day wan ... trie

變量

name = "xiaochui"

name2 = name

print("My name is",name2)

Myname is xiaochui

---------------------------------------------------------------------------------------------------------------

name = "xiaochui"

name2 = name name2直接指向"xiaochui" 不是先指向name

name = "xiao" name 覆蓋了之前的變量,現在是"xiao", 而name2 還是"xiaochui"

print("My name is",name)

My name is xiao

-----------------------------------------------------------------------------------------------------------------

格式化輸出

name = input("name:")

age = input("age:") 下面使用age:%d的話會報錯,默認是字符串,而%d只能接收數字

sge = int (input("age:"))

job = input("job:")

salary = input("salary:")

info = ‘‘‘

-----------------------info of %s---------- # s==string

Name:%s

Age:%s

Age:%d #d只能接收數字,那麽上面的age=input("age:")要修改,否則報錯 age=int(input("age":))

Job:%s

Salary:%s

‘‘‘ %(name,name,age,job,salary)

print(info)

info2 = ‘‘‘

-----------------------info of {_naem}------------

Name = {_name}

Age = {_age}

Job = {_job}

Salary = {_salary}

‘‘‘ .format(_name = name,

     _age = age,

     _job = job,

     _salart = salart)

print(info2)

------------------------------------------------------------------------------------------------------------------

密碼看不了==密文

導入模塊 import ****

import getpass

_username = "xiao"

_password = "chui"

username = input("username:")

password = input("password:")

if _username == username and _password == password:

  print("Welcome user {name} login...".format(name= username))

else:

  print("Invalid username or password!")

---------------------------------------------------------------------------------------------------------------------------

猜年齡

age_of_xiaochui = 18

count = 0

while True"

  if count == 3:

    break

  guess_age = int(input("guess:"))

  if age_of_xiaochui == guess_age:

  print("yes,you got it!")

  break

  elif guess_age > age_of_xiaochui:

  print("think samaller...")

  else:

  print("think bigger!")

  count += 1

else:

  print("you have tried too man yimes..fuck off")

不退出程序玩

age_of_xiaochui = 18

count = 0

while count <3:

  guess_age = int(input("guess_age:")

  if age_of_xiaochui == guess_age:

  print("yes,you got it!")

  break

  esif guess_age > age_of_xiaochui:

    print("think smaller...")

  else:

    print("think bigger!")

  count += 1

  if count == 3:

    countine_confirm = input("do you want to keep guessing..?")

    if countine_confirm != "n":

      count = 0

else:

  print("you have tried woo many yimes..fuck off")

------------------------------------------------------------------------------------------------------

forx循環

for i in range(10): # i 是臨時變量

  print("loop",i)

----------------------------------

age_of_xiaochui = 18

for i in range(3):

  guess_age = int(input("guess_age:"))

  if age_of_xiaochui == guess_age:

  print("yes,you got it!")

  break

  elif guees_age < age_of_xiaochui:

    print("think smaller...")

  else:

    print("think bigger!")

else:

  print("you have tried too many yimes..fuck off")

Pyhton基礎 day1