With the time goes on to the second semester, I started a brand new IT coures, so I took the opportunity to review and organize the Key Terms of programming according Python.


print("Let's start!")


Varible

Customize a value and assign it to another specified name, and it can be easily called repeatedly​

name = "Vincent"
age = 16

Varible


String

String is a text type, usually quoted with quotation marks, he is an immutable type, common language output text​

str1 = "Vincent"
str2 = "Grade 11"
print(type(str1))
print(type(str2))

String


Input

The Input function can record and save your input, and can assign a value to a variable and output​

print("Enter your name:")
x = imput()
print("Hello ", X)

Input


Loop

Let the program repeat some of the same operations to traverse the index array or increment the value​

sports = ["fishing", "boating", "swmming", "skating"]
for i in sports:
   print(i)          # for loop


x= 1
while x<7:
   print(x)
   x += 1            # while loop

Loop


Number

A type of data that can only store numeric types, there are three main numeric types in python ​

  • int ​
  • float ​
  • complex​
x = 10    # int
y = 6.3   # float
z = 2j    # complex 

Number


List

A list is an ordered and changeable collection, which can hold numbers and string types, and can be obtained by position index​

sports = ["fishing", "boating", "swmming", "skating"]

List


Bool

Bool represents one of two values: True or False. 1 means True, 0 means False, can be used to judge the result of the operation​

x = 1
y = 0
z = "hello"

Bool


Function

Integrate multiple different instructions into a function object, and call them together to form a new instruction, which can pass in specified parameters, which can reduce the amount of repeated code​

def my_function(name = " Vincent", country = " Canada" ):
  print("Hello, I am a function made by" + name)
  print("I am from" + country)

my_function()
print("-"*45)
my_function(" Hover", " US")

Function


Braches

Judge the data through if...else... or elif, and eliminate the condition in turn to enter the next judgment, and finally get the desired result

score = 78
if score >= 87 and score <= 100:
   print("Your mark is A")
elif score >= 72 and score < 87:
   print("Your maek is B")
elif score >= 60 and score < 72:
   print("Your maek is C")
elif score >= 0 and score < 60:
   print("Your maek is F")
else:
   print("Unexpected score")

Braches


While loop​

Similar to the for loop, it repeats some of the same operations, thereby simplifying the amount of code​

i = 1 
while i < 100000000000000:
  print(i)
  i += 1
else:
  print("loop end")

While loop

⬇ have a try ⬇

This is a simple banking system that includes functions such as login, deposit, withdraw, and find password. Apply all the above knowledge

username = ["Vincent", "Bob", "Hover"]
password = 123456
balance = 100      # user information

# login
input_username = input("Username:")
for index_all_usernames in username:
    if input_username == index_all_usernames:
        input_password = input("password:")
        if int(input_password) == password:
            print("Login successfully")

            # deposit
            select = input("Choose your action: (1):deposit、(2):withdraw、(4):forget password、(3)quit")
            if select == "1":
                depoit_money = input("Type the amount you want to deposit")
                depoit_money = int(depoit_money)
                balance = depoit_money + balance
                print("Your current account balance is", balance)

            # withdraw
            elif select == "2":
                withdraw_money = input("Type the amount you want to withdraw:")
                withdraw_money = int(withdraw_money)
         # Determine whether the balance is greater than the money withdrawn
                if balance >= withdraw_money:
                    balance = balance - int(withdraw_money)
                    print("Your current account balance is", balance)
                else:
                    print("You don't have enough money,your current account balance is", balance)

            # find password
            elif select == "3":
               print("Your current password is", password)

            # quit system
            elif select == "4":
                print("Your system has been safety quit")

        else:
            print("Your password is wrong")
        break
        # end [for loop]

else:
    print("Can't find your username in our system")

Hope you can get interested in programming

Last modification:April 27th, 2021 at 11:36 pm
如果觉得我的文章对你有用,请随意赞赏