Cov txheej txheem:

Python Tutorial: 6 Kauj Ruam
Python Tutorial: 6 Kauj Ruam

Video: Python Tutorial: 6 Kauj Ruam

Video: Python Tutorial: 6 Kauj Ruam
Video: Python Tutorial for Beginners 6: Conditionals and Booleans - If, Else, and Elif Statements 2024, Lub Xya hli ntuj
Anonim
Python Tutorial
Python Tutorial

Nyob zoo! Zoo siab txais tos rau kuv cov lus qhia thib ob thiab qhov no yuav yog qhov pib ntawm nab hab sej.

Hauv cov lus qhia no, Kuv yuav qhia koj cov hauv paus ntawm cov loops, cov tswv yim thiab cov khoom tso tawm, kom lub khoos phis tawj hais ib yam dab tsi, yog cov lus hais thiab qhov txawv. Hauv qhov kawg peb yuav siv GUIs lossis cov duab siv sib cuam tshuam nrog cov cuab yeej hu ua easygui.

Ib zaug ntxiv, tawm lus hais txog yuav ua li cas kuv yuav tsum txhim kho thiab cov lus nug ntawm cov khoom koj tsis nkag siab

muaj kev lom zem!

Kauj Ruam 1: Hais ib yam dab tsi

Hais ib yam dab tsi!
Hais ib yam dab tsi!

Hauv theem no, peb yuav kawm paub ua kom nab nab hais dab tsi. yooj yim heev txhua yam koj yuav tsum ntaus ntawv yog yam koj xav hais, tom qab ntawd muab qhov no nyob ib puag ncig nws. print ('') cov. piv txwv li luam tawm ('nyob zoo ntiaj teb'). yog tias koj tab tom siv nab hab sej 2 koj yuav sau cov ntawv "nyob zoo ntiaj teb" ntaus qhov no rau hauv lub qhov rais plhaub - tus uas tawm los thiab nias nkag mus.

koj mus! koj thawj txoj haujlwm

Kauj Ruam 2: Nov Yog Qhov Loopy Me…

Qhov no yog Me ntsis Loopy…
Qhov no yog Me ntsis Loopy…

ua ntej tshaj plaws, nyem Ctrl+N uas yuav coj koj mus rau cov ntawv tshiab. txuag nws raws li loops.py tus.py ntsis qhia tias qhov no yog cov ntaub ntawv sej. qhov no yog thawj hom voj.

rau kuv hauv ntau (1, 101):

luam tawm (kuv)

qhov no yuav mus zoo li no

1

2

3

4

5

6

7

100

qhov sib txawv, kuv, yuav cia li ntxiv ib qho txhua lub sijhawm nws loops siab txawm hais tias, nws tsis luam tawm 101.

nov yog lwm lub voj

kuv = 1

thaum kuv <100:

kuv = i+1

luam tawm (kuv)

qhov no zoo sib xws rau saum toj kawg nkaus. peb hu rau sab saum toj ib qho rau lub voj thiab hauv qab ib lub voj.

lub voj thaum suav nrog 100 yog li tsis tas yuav ua thaum kuv <101.

Kauj Ruam 3: Tawm tswv yim thiab tso tawm

Tawm tswv yim thiab tso tawm
Tawm tswv yim thiab tso tawm

txoj haujlwm no yuav ua rau lub khoos phis tawj nug koj ib yam thiab teb rau lo lus teb.

qhov no yog ib qho piv txwv

f = input ('dab tsi yog koj lub npe') <----------- teeb tsa qhov sib txawv thiab qhia txog kev nkag

print ('nyob zoo', f) <------------------------- luam tawm qhov sib txawv uas tau nkag los ntawm tus neeg siv nrog nyob zoo rau pem hauv ntej

cov zis yuav tsum yog ib yam zoo li no:

>> koj lub npe hu ua Larry

>> nyob zoo Larry

raws li koj tuaj yeem pom cov tswv yim tsis zoo heev. yog tias koj xav tau chaw, tso qhov kawg ntawm thawj kab:

f = input ('koj lub npe yog dab tsi')

yog tias koj xav kom nws nug koj hnub nyoog lossis pes tsawg mars tuav koj muaj, ua qhov no:

f = int (input ('koj muaj hnub nyoog li cas'))

yog tias nws yog tus lej lej, ua:

f = float (input ('enter a decimal number'))

koj nyob li cas

Kauj Ruam 4: Yog los ntawm Rudya ----- tsis Yog Tsis Yog! Nws yog Python U Dimwit

Yog los ntawm Rudya ----- tsis yog Tsis yog! Nws yog Python U Dimwit!
Yog los ntawm Rudya ----- tsis yog Tsis yog! Nws yog Python U Dimwit!

yog tias nqe lus feem ntau siv los sib piv 2 cov hlua lossis cov lej.

nws feem ntau tuaj tom qab kev tawm tswv yim

ntaus qhov program hauv daim duab thiab koj yuav tuaj yeem pom muaj txiaj ntsig yog tias tuaj yeem yog thiab qee yam uas koj tsis xav tau …

ib txwm ntaus:

yog*ib yam*, =,! =, =*lwm yam*:

print (*ib yam*'yog dab tsi tshaj'*lwm yam*)

Kauj Ruam 5: Pib ntawm Easygui

Pib ntawm Easygui
Pib ntawm Easygui

easygui yog tus qauv uas yuav tsum tau rub tawm.

rub nws yog tias koj tsis muaj nws ces sim qhov program no.

ntshuam easygui

easygui.msgbox ('nyob zoo lub ntiaj teb')

nws yuav tsum tuaj nrog qee yam zoo li hauv daim duab.

Kauj Ruam 6: Dab Tsi Ntxiv?

yog li ntawd nws yog tam sim no.

khaws lub qhov muag qhib, kuv yuav ua lwm yam kev qhia xws li windows batch thiab lwm yam lus. nyob zoo!

ua tau zoo tiag tiag uas yog ntau yam los kawm!

sib nrug los ntawm cov ntawv qhia uas kuv tau sau, muaj ntau qhov kev qhia ntawm ntau yam lus. yog tias koj xav tau txais pdf nrog cov ntsiab lus ntau ntxiv, kuv pom zoo kom Nyob Zoo Phau Ntawv Ntiaj Teb 2 uas muaj nyob hauv is taws nem - tsuas yog tshawb nws.

yog tias koj tsis tau tswj kom nruab easygui thiab xav tau, rub qhov txuas no:

Kuv kuj tau tsim kuv tus kheej lub npe hu ua PyCal uas cia koj xam cov khoom nrog cov qauv nyuaj xws li Pythagoras 'theorem thiab thaj tsam ntawm lub voj voog.

Pom zoo: