Python chapter 2/part 2

Descrição

nothing programming tech rocket (Python) Notas sobre Python chapter 2/part 2, criado por yomum 21 em 20-07-2016.
yomum 21
Notas por yomum 21, atualizado more than 1 year ago
yomum 21
Criado por yomum 21 aproximadamente 8 anos atrás
16
1

Resumo de Recurso

Página 1

The If-Else statement is the most basic of all the control flow statements. It tells your program to execute a certain section of code only if a particular condition evaluates to true.e.g.mood = input("how are you(good or bad)").lower()if(mood == "good") or (mood == "g"): print("Glad to hear")elif(mood == "bad") or (mood == "b"): print("Cheer up")else: print("answer me now")conditional statements: statements that give the user options and interactivity.lower()=automatically changes it to a lower case valuee.g. mood = input("how are you(good or bad)").lower().upper()=changes it to upper case\e.g.mood = input("how are you(good or bad)").upper()lists=used to store things in pythonDeclaring lists in python= e.g. cars=["off road","sport","muscle","Hybrids"]Using the list=for first one you have to 0 and then 1 then 2 then 3 etc.Calling the list=In order to call you must call it by it's index numbere.g. cars=["off road","sport cars","muscle cars","Hybrids"]cars[1]this is calling sport cars[random.randint()]=calls random things from list e.g.cars=["off road","sport cars","muscle cars","Hybrids"]print(cars[random.randint(0,3)])For loops: extremmly popular and often used to loop through lists; or through a rangee.g. cars=["off road","sport cars","muscle cars","Hybrids"]for name in cars: print("the types of cars are:"cars)range()=used to tell how many times the loop repeatswhile loops: a types of loop that directs it true or falsedecremeter: used to edit a variablee.g.10_car_garages=10while 10_car_garages > 0: 10_car_garages = 10_car_garages - 1time class= used to add a delaytime.sleep=used to sleepe.g. 10_car_garages=10while 10_car_garages > 0: 10_car_garages = 10_car_garages - 1 time.sleep(1) sleeps for 1 secondmaxLengthList=maxium number of things on a liste.g. maxLengthList = 10len()=the length of a compared variablee.g.cars = []maxLengthList = 10while len(cars) < maxLenghtList: item = input("choose a car")print(cars)break=break the loopitem= enters an item to a listappend()=The method append() appends(add something in an end of a written document) a passed obj into the existing list.e.g. cars.append(item)fuction syntax:def fuctionname (parameters): [fuction body] return[experesion]e.g.def cars(types): print("Play game?") print("the game has crashed")

Semelhante

Common Technology Terms
Julio Aldine Branch-HCPL
Project Communications Management
farzanajeffri
Network Protocols
Shannon Anderson-Rush
Abstraction
Shannon Anderson-Rush
Computing
Kwame Oteng-Adusei
HTTPS explained with Carrier Pigeons
Shannon Anderson-Rush
Introduction to the Internet
Shannon Anderson-Rush
Construcción de software
CRHISTIAN SUAREZ
Historical Development of Computer Languages
Shannon Anderson-Rush
Useful String Methods
Shannon Anderson-Rush
Web Designing & Development Full Tutorial
Nandkishor Dhekane