程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python-Level1-day02: Basic operations on data: variables and their memory map, core data types, operators

編輯:Python
"""
1.獲取資源
2.The code execution process is compiled and interpreted
3.使用集成開發環境pycharm
"""
"""
Currency conversion device
"""
# 1.獲取數據
usa_money = float(input("please "))
# 2.邏輯運算
china_money = usa_money * 6.18
# 3.輸出結果
print("answer = " + str(china_money))
​
"""
  函數 print
  1.字面含義:打印內容
  2.作用:Display the program contents to the terminal
  3.語法:print("hello")
  4.適用:When you need to print the results
"""
​
print("hello")
"""
  print verse
"""
print("             登高 ")
print("           作者:杜甫 ")
print(" 風急天高猿嘯哀,渚清沙白鳥飛回.")
print(" 無邊落木蕭蕭下,不盡長江滾滾來.")
print(" 萬裡悲秋常作客,百年多病獨登台. ")
print(" 艱難苦恨繁霜鬓,潦倒新停濁酒杯.")
​
"""
函數 - input
1.字面含義:輸入東西
2.作用:終端輸入
3.語法格式:返回字符串
4.適應性:when you need to get data
"""
name = input(" please")
print("input is "+name)
​
#Determine the composition of English sentences:I kiss you
zhuyu = input("zhuyu")
weiyu = input("weiyu")
bingyu = input("bingyu")
print("zhu yu :" + zhuyu)
print("weiyu :" + weiyu)
print("bingyu :" + bingyu)
​
"""
  變量
      The program runs in memory
      程序(行為)在處理數據
      語法:變量名稱 = 數據
​
"""
#創建變量:memory level to understand it
#pythonThe variables in do not store the data itself,Just store its address,
# Give this address space an aliasname
#If the data has no variables go grab it,Then this data will be automatically recycled when it is used up
​
#Draw your own memory map
a = "悟空"
b = "八戒"
d = b
c = a + b
b = "唐僧"
print(c)
​

 

 

"""
  Variable memory stick practice
"""
​
hubei = "湖北"
hunan = "湖南"
hunan = "湖南省"
hunan = hubei
print(hunan)

 

 

​
#Draw a memory map to show the result
beijing,region = "北京","市"
beijing_region = beijing+region
region = "省"
print(beijing_region)
del beijing
print(beijing_region)
"""
  del
      用於刪除變量,同時解除與對象的關聯.如果可能則釋放對象
"""
name01 = name02 = "悟空" # Create two variables in succession while pointing to the data
del name01 # 引用計數為1 刪除變量 數據存在
del name02 # 引用計數為0 刪除數據與變量
​
name03, name04 = "a", "b"
del name03, name04
# print(name03)
​
"""
  核心數據類型
      1.字符串
      2.整數類型
      3.浮點類型
  類型轉換(長得像)
      1.String to integer type,Integer type to string
      2.字符串轉浮點數,浮點數轉字符串
      3.Integer type to floating point,Floating point to integer type
"""
str1 = "hello"
str2 = "21"
number1 = 1
number2 = 1.0
​
a = int("123")
print(a)
​
b = int(1.9) # 向下取整
print(b)
​
a = float("123")
print(a)
​
"""
練習:Enter the unit price of the product in the terminal、Quantity purchased and amount paid.計算應該找回多少錢.
效果: 請輸入商品單價:5 請輸入購買數量:3
      請輸入支付金額:20 應找回:5.0
"""
danjia = float(input("please danjia"))
num = int(input("please num"))
pay = float(input("please pay"))
print("zhao ling " + str(pay - danjia * num))
​
"""
  運算符
      算術運算符
          + 加法
          - 減法
          * 乘法
          / 除法:結果為浮點數
            // 整除:除的結果去掉小數部分
            % 求余
            ** 冪運算
      增強運算符
          y += x 相當於 y = y + x
          y -= x 相當於 y = y - x
          y *= x 相當於 y = y * x
          y /= x 相當於 y = y / x
"""
print(5 ** 2)
print(5 // 2) # 小數商,向下取整
print(5 / 2)
​

 

 

 

"""
      Enter a number of confirmed cases in the terminal and then enter a number of cured patients,Print the cure scale
      格式:The cure rate is xx%
      效果:Please enter the number of confirmed cases:500 Please enter the number of recovered patients:495 The cure rate is 99.0%
"""
quezheng = int(input("quezheng people"))
zhiyu = int(input("zhiyu people"))
print("zhi yu bi li " + str(zhiyu / quezheng * 100) + "%")
​
"""
  Ancient scales,A pound and sixteen taels.Get two in the terminal,計算幾斤零幾兩.
          效果:Please enter a total of two numbers:100 結果為:6 斤 4 兩
"""
liang = int(input("please liang"))
print(str(liang//16)+"jing "+str(liang%16)+"liang")
"""
Velocity and displacement formulas for uniformly variable linear motion: 位移 = 初速度 × 時間 + 加速度 * 時間的平方 / 2
  已知(在終端中錄入):時間、初速度 加速度
  計算:位移
"""
chushudu = float(input("chushudu"))
time = float(input("time"))
jiashudu = float(input("jiashudu"))
print(chushudu * time + jiashudu * (time ** 2) / 2)
​
"""
Enter a four-digit integer into the terminal,計算每位相加和.
例如:錄入 1234,打印 1+2+3+4 結果
效果:請輸入四位整數:1234 結果是:10
"""
num = int(input("please"))
num0 = num // 1000
num1 = num % 1000 // 100
num2 = num % 100 // 10
num3 = num % 10
print(num0 + num1 + num2 + num3)
​
# 變量少,更加節約內存,優秀啊
result = 0
result += num % 10
result += num % 100 // 10
result += num % 1000 // 100
result += num // 1000
print(result)
​

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved