重新學習python05

2021-10-04 04:41:19 字數 2822 閱讀 1842

測試題:

0. 在 python 中, int 表示整型, 那你還記得 bool 、 float 和 str 分別表示什

麼嗎?int 表示整形

bool 布林型

float 浮點型

str 字串

1. 你知道為什麼布林型別 (bool) 的 true 和 false 分別用 1 和 0 來代替

嗎?true 表示條件成立, 在python中1即可表示這個意思?

false表示條件不成立,在pytho中0表示這個意思?

2. 使用 int() 將小數轉換為整數,結果是向上取整還是向下取整呢?

a = 5.7

b = int(a)

那麼b的值為5

所以向下取整

3. 我們人類思維是習慣於「四捨五入」法,你有什麼辦法使得 int() 按照「四

舍五入」的方式取整嗎?

對小數點後的第乙個數字取出來 與數字4進行比較,若大於4,則進一位;若小於4,則退一位;

兩者都可以;

5. python3 可以給變數命名中文名,知道為什麼嗎?

pyhton3 原始碼檔案預設使用 utf-8 編碼(支援中文)

補充:s 為字串

s.isalnum() 所有字元都是數字或者字母,為真返回 ture ,否則返回 false。

s.isalpha() 所有字元都是字母,為真返回 ture ,否則返回 false。

s.isdigit() 所有字元都是數字,為真返回 ture ,否則返回 false。

s.islower() 所有字元都是小寫,為真返回 ture ,否則返回 false。

s.isupper() 所有字元都是大寫,為真返回 ture ,否則返回 false。

s.istitle() 所有單詞都是首字母大寫,為真返回 ture ,否則返回 false。

s.isspace() 所有字元都是空白字元,為真返回 ture ,否則返回 false 。

__author__ = '18800'

#coding=utf-8

import random

times = 3

secret = random.randint(1,10)

print("secret的值為: %d" %secret)

print("*****==i love fishc job room*****")

guess = 0

print("猜猜我現在內心裡想的是哪乙個數字: ", end = "")

while(guess != secret) and (times > 0) :

temp = input()

# guess = int(temp)

while not temp.isdigit():

temp = input("抱歉輸入有錯,請輸入乙個整數: ")

guess = int(temp)

times -= 1

if guess == secret :

print("臥槽,你簡直是我內心的蛔蟲!")

print("猜中,也沒有獎勵!")

else :

if guess > secret :

print("大了 大了")

else :

print("小了 小了")

if times > 0 :

print("try again!")

else :

print("no chance for u !")

__author__ = '18800'

#coding=utf-8

"""temp = input("不妨猜一下內心想的哪個數字:")

while type(temp) != type(1) :

print("抱歉,輸入不合法, ", end="")

temp = input("請輸入乙個整數: ")

""""""

temp = input("不妨猜一下內心想的哪個數字:")

while not isinstance(temp, int):

print("抱歉,輸入不合法, ", end="")

temp = input("請輸入乙個整數: ")

"""

# solution1

year = input("請輸入乙個數:")

temp = int (year)

if ( temp % 400 == 0 ) :

print("是閏年!")

elif ( temp % 4 == 0) and (temp % 100 != 0) :

print("是閏年!")

else :

print("不是閏年!")

"""# solution2

year = input("請輸入乙個數:")

temp = int (year)

temp1 = (temp % 4 == 0 and temp % 100 != 0)

temp2 = (temp % 400 == 0)

if (temp1 or temp2) :

print("是閏年!")

else :

print("不是閏年!")

重新學習makefile

今天回顧了一下makefile,做下筆記 首先準備幾個簡單的檔案 add.c head.h main.c mul.c sub.c 然後第一版 makefile 然後第二版 gcc c main.c o main.o 然後第三版 makefile 的語法跟shell 很像 第四版 目標 依賴 tab ...

重新學習struts

這就是所謂的一邊工作一邊學習。今天準備把給公司寫個管理頁面,按照之前的路數,寫起來應該挺快,但是不太規範。也就沉下心來學習一下了。第二個學習的是,異常處理。也是在學校的時候,聽老師說過,struts2有提供乙個異常處理機制。平常我們有些異常處理,會在 中寫try catch。public strin...

重新學習Python01

測試題 0.python 是什麼型別的語言?物件導向語言 1.idle 是什麼?python編譯器,直譯器 2.print 的作用是什麼?列印輸出 3.python 中表示乘法的符號是什麼?4.為什麼 print i love fishc.com 5 可以正常執行,但 print i love fi...