1.python input and formatted output.
#!/usr/bin/evn python
#-*-Coding:utf-8-*-
# author:aron1) Input Enter name = input ("Name:")
Age = Input ("Age:")
Job = input ("Job:")
Salary = input ("Salary:")
Input format bit str
Format conversion:
age = Int (input ("Age:"))
Enter as int
2) Three ways to format the output
①
info = " "
------Info of {_name}------
Name:{_name}
Age:{_age}
Job:{_job}
Salary:{_salary}
-----------------------------
". Format (_name = name,
_age = age,
_job = job,
_salary = Salary
)
②
info = " "
------Info of {1}------
name:{2}
Age:{3}
Job:{4}
salary:{5}
-----------------------------
". Format (name,name,age,job,salary)
③
info = " "
------Info of%s------
name:%s
age:%s
job:%s
salary:%s
-----------------------------
"% (name,name,age,job,salary)
2.while loops and for loops
1) while loop
_username = ' Aron '
_password = ' abc123 '
count = 0
while True:
Password = input ("Password:")
if _username = = Username and _password = password:
print (" Welcome user {name} login ... ". Format (name=username))
Brea K
else:
print ("Invalid username or password! Re-enter ")
count + = 1
if Count = = 5:
break # (jump out of the Loop) #continue (skip this loop and go to the next loop)
Shorthand:
Age_of_oldboy = 56
Count = 0
While Count < 3:
guess_age = Int (input ("Guess Age:"))
if guess_age = = Age_of_oldboy:
Print ("Yes,you got It")
Break
Elif guess_age > Age_of_oldboy:
Print ("Think smaller ...")
Else
Print ("Think birgger!")
Count + = 1
if Count = = 3:
Countine_confirm = input ("Does want to keep guessing?")
If countine_confirm! = ' n ':
Count =0
Else
Print ("You have tried too many times. Fuck off ")
2) for Loop
Age_of_oldboy = 56
For n in range (0,10,2):
Print ("Loop", N)
For I in range (3):
guess_age = Int (input ("Guess Age:"))
if guess_age = = Age_of_oldboy:
Print ("Yes,you got It")
Break
Elif guess_age > Age_of_oldboy:
Print ("Think smaller ...")
Else
Print ("Think birgger!")
Else
Print ("You have tried too many times. Fuck off ")
Python first day