0% found this document useful (0 votes)
41 views2 pages

Print: "Brand" "Ford" "Model" "Mustang" "Year"

The document provides examples of Python dictionaries, elif statements, while loops, for loops, and nested loops. It includes 2 examples each of dictionaries, elif statements, while loops, for loops, and nested loops. The dictionaries store key-value pairs, the elif statements allow checking multiple conditional expressions, the while loops repeat until a condition is false, the for loops iterate over lists, and the nested loops have loops within other loops.

Uploaded by

Car Lo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views2 pages

Print: "Brand" "Ford" "Model" "Mustang" "Year"

The document provides examples of Python dictionaries, elif statements, while loops, for loops, and nested loops. It includes 2 examples each of dictionaries, elif statements, while loops, for loops, and nested loops. The dictionaries store key-value pairs, the elif statements allow checking multiple conditional expressions, the while loops repeat until a condition is false, the for loops iterate over lists, and the nested loops have loops within other loops.

Uploaded by

Car Lo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

2 example of Python Dictionaries


a. thisdict = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}
print(thisdict)

b. released = {

"iphone" : 2007,
"iphone 3G" : 2008,
"iphone 3GS" : 2009,
"iphone 4" : 2010,
"iphone 4S" : 2011,
"iphone 5" : 2012
}
print released

2. ELIF and 2 example


The elif is short for else if. It allows us to check for multiple expressions. If the condition for if is
False, it checks the condition of the next elif block and so on. If all the conditions are False, body of
else is executed.
Ex.
a. for i in range(-5, 5):
  if i > 0:
    print("YES")
  elif i == 0:
    print("WHATEVER")
  else:
    print("NO")
b. num = 3.4
if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")
3. 2 example of python while loop
a. i = 1
while i < 6:
  print(i)
  i += 1
b. x = 0;
while (x < 5):
print(x)
x += 1
4. 2 example of python for loop
a. fruits = ["apple", "banana", "cherry"]
for x in fruits:
  print(x)
b. color_list = ["Red", "Blue", "Green", "Black"]
for c in color_list:
print(c)
5. 2 example of python nested loop
a. i = 2
while(i < 100):
j=2
while(j <= (i/j)):
if not(i%j): break
j=j+1
if (j > i/j) : print i, " is prime"
i=i+1
print "Good bye!"

b. x = int(input('Enter a number: '))


while x != 0:
for y in range (1, x):
print (y)
y+=1
x = int(input('Enter a number: '))

You might also like