What is a variable in your words?
What are the variables in that script?
print('Hello world') students = ['Jack', 'Adam', 'Brad'] for s in students: print('Hello', s)
# first block if number % 2 == 0: # mind the indentation! print('The number is even') # 2nd block else: # an other block (indented!) print('The numver is odd')
Is producing a sequence of integers (whole numbers) on which we can iterate
>>> print(range(5)) range(0, 5) >>> print(list(range(5))) [0, 1, 2, 3, 4] >>> for i in range(3): ... print(i) ... 0 1 2
Given an integer, n, perform the following conditional actions:
n = int(input())
What are the 2 ways of creating loops in python?
How would you make this code more concise (1)? And more flexible if for example the program can take any number of sales (2)? Think DRY!
sale_1 = int(input('Enter sale price 1: ')) sale_2 = int(input('Enter sale price 2: ')) sale_3 = int(input('sale price 3: ')) print('The average sale was ', (sale_1 + sale_2 + sale_3) / 3)
Is the program calling the function here?
def hello(): print('Hello') a = hello
You are given the year, and you have to write a function to check if the year is leap or not.
def is_leap(year): leap = False # Write your logic here: year divisible by 400 or year NOT divisible by 100 and divisible by 4 return leap year = int(input()) print(is_leap(year))
Can you find on google which python builtin module you could use to say if a year is a leap year?
The program reads a letter of the alphabet from the user. If the user enters a, e, i, o or u then your program should display a message indicating that the entered letter is a vowel.
Define a function and call it when the program is run
letter = input('Enter a letter') # your code
What is a python module?
What do we have to do before being able to use a library or a python module?
Ask a user to enter 1 if he wants to flip a coin or 2 if he wants to roll a dice and print the number obtained or 'tail' or 'face'
Create one function for each choice. Use the random library (use the keyword import)
# import libraries at the top of the program # write your functions here choice = int(input('Enter 1 to flip a coin or 2 to roll a dice')) if choice == 1: pass # replace with your code else: pass #replace with your code
What are the simple builtin class in python?
What are the container types?
What is an object in your own words?
How would you create a string object?
How would you create a list object?
How would you create a custom object?
Create 3 classrooms objects that have each a name, a schedule and a building.
How do you add/access element to a list?
How do you add/access element to a dictionary?
Suppose you have the following as input:
4 7 9 1 3 2 5
Write a program that gives the 2nd largest item:
Hint: input is returning a string, to transform a string to a list, use split()
Define and call a function
Create a currency converter using the http://api.fixer.io/latest api
Install the requests library
import json import requests r = requests.get('http://api.fixer.io/latest') d = json.loads(r.content) # your code here:
Use the deserialize data from the api and write them in a file called 'countries'.
Instead of using urllib, can you rewrite the program using the requests library?
import json from urllib import request infile = request.urlopen( 'https://restcountries.eu/rest/v1/all') content_as_python_obj = json.loads(infile.read().decode()) # to complete: create the file