You are on page 1of 2

print(f"\t{name.

title()}, Thank you for


# Using range() function to make list choosing {language.title()}")
for value in range(1, 9): else:
print(value) print(f"\t{name.title()}, Please take the
poll!")
# Using range() to make a list of numbers
numbers = list(range(1, 10)) # Finding friends who don't have any favorite
print(numbers) language

#Printing even numbers for friend in sorted(friends):


even_numbers = list(range(2, 11, 2)) print(f"\n{friend.title()}")
print(even_numbers) if friend in fav_languages.keys():
value = fav_languages[friend]
# LIST COMPREHENSIONS -- combines for print(f"\tThank you for choosing
loop and creating new element in a list {value.title()}")
squares = [value**2 for value in range(1, 7)] else:
print(squares) print(f"\tSorry you donot have any fav
# Create dictionary using multiple lines - Follow language")
accurate Indentation
fav_languages = { # Looping through all values except keys --
'palash' : 'python', Using values() method
'ullash' : 'java', print(f"\nThe following languages have been
'rishi' : 'ruby', mentioned:")
'upoma' : 'c' for language in fav_languages.values():
} print(f"\t{language.title()}")
#lang = fav_languages['upoma'].title()
#print(f"Upoma likes {lang}") # For retrieving UNIQUE values use set function
# for language in set(fav_languages.values())
#Use get() method, when we donot know
whether any key exists in dictionary # Building a set directly using {} to include
#palash_lang = unique values
fav_languages.get('Palash'.lower()) # languages = {'python', 'C', 'java', 'ruby'}
#print(f"\nPalash Likes {palash_lang.upper()}")
#shilpi_lang = fav_languages.get('shilpi', 'No # Create lists inside a dictionary and use for loop
Inforamtion about shilpi')
#print(shilpi_lang) fav_languages = {
'palash' : ['python', 'java script','java'],
# Use for loop to retrieve every key-value from 'ullash' : ['java'],
dictionary 'rishi' : ['ruby', 'python', 'html'],
#for name, language in fav_languages.items():ltt 'upoma' : ['c', 'html']
# print(f"\n{name.title()}'s favorite language is }
{language.title()}") for name, languages in fav_languages.items():
if len(languages) > 1:
# Looping through all the keys of a dictionary. print(f"\n{name.title()}'s favorite languages
#We can use keys() method also. Example for are:")
names in fav_language.keys() for language in languages:
#for name in fav_languages: print(f"\t{language.title()}")
# print(name.title()) else:
print(f"\n{name.title()}'s favorite language
# Use two loops and conditional if statement is:")
friends = ['palash', 'upoma', 'ullash', 'suchi'] print(f"\t{languages[0].title()}")
for name in fav_languages:
print(f"\n{name.title()}")
# Use while loop in input() function
if name in sorted(friends):
language = fav_languages[name] prompt = "\nEnter your name."
prompt += "\nEnter 'quit' to bust off. "
message = ""
while message != 'quit':
message = input(prompt).lower()

if message != 'quit':
print(message.title())
else:
print("You are busted off!!!")
# Using a Flag to control loop

prompt = "\nEnter your name."


prompt += "\nEnter 'quit' to bust off. "

active = True
while active:
message = input(prompt).lower()

if message == 'quit':
active = False
print("You are busted!!!")
else:
print(message)

You might also like