Python first day

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.