Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # last lecture / coding workshop, 9.12.2021
- # some simplified restaurant data
- r1 = {
- "name": "Cheapy Restaurant",
- "rating": 3.6
- }
- r2 = {
- "name": "Expensivo",
- "rating": 4.7
- }
- r3 = {
- "name": "WhatIsThis-Restaurant",
- "rating": 1.2
- }
- # all restaurants into the list
- restaurants = [r1, r2, r3]
- # ask all the questions from user
- stars = input("How many stars at least (1-5)?\n")
- stars = int(stars)
- # then go through all restaurants
- for company in restaurants:
- # assume the restaurant is a matching restaurant in the beginning
- good_restaurant = True
- # for each question, have a separate if-statement
- # and try to flip the boolean into False
- if company['rating'] < stars:
- # rating didn't match, flip to False
- good_restaurant = False
- # if none of the previous if-statements flipped the boolean, print the name
- if good_restaurant:
- print(company['name'])
- # NEW FILE
- # filter out all but numbers from string
- # testing with a string of hours, minutes and seconds
- test = "10h 33min 25sec"
- # split into three parts by space character
- parts = test.split(" ")
- # go through each piece, in this case ['10h', '33min', '25sec']
- for t in parts:
- # remove all non-numeric characters
- # => results in a string
- numeric_filter = filter(str.isdigit, t)
- # numeric_filter is a list of each number
- # => combine them back to one string
- numeric_string = "".join(numeric_filter)
- # print out numbers only
- print(numeric_string)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement