This repository has been archived by the owner on Oct 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
program.py
114 lines (94 loc) · 3.04 KB
/
program.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
my_menu = {}
my_menu["breakfast"] = "Corn flakes"
my_menu["lunch"] = "Falukorv och potatis"
my_menu["dinner"] = "Hamburgare"
print(my_menu)
print(f'Till middag äter jag nästan alltid {my_menu["dinner"]}')
#{'breakfast': 'Corn flakes', 'lunch': 'Falukorv och potatis', 'dinner': 'Hamburgare'}
#Till middag äter jag nästan alltid Hamburgare
my_menu["snacks"] = "Chips"
print(my_menu)
# {'breakfast': 'Corn flakes', 'lunch': 'Falukorv och potatis', 'dinner': 'Hamburgare', 'snacks': 'Chips'}
my_menu["dinner"] = "Köttfärssås och spagetti"
# {'breakfast': 'Corn flakes', 'lunch': 'Falukorv och potatis', 'dinner': 'Köttfärssås och spagetti', 'snacks': 'Chips'}
del my_menu["snacks"]
print(my_menu)
# {'breakfast': 'Corn flakes', 'lunch': 'Falukorv och potatis', 'dinner': 'Köttfärssås och spagetti'}
my_menu_keys = my_menu.keys()
print(my_menu_keys)
#dict_keys(['breakfast', 'lunch', 'dinner'])
my_menu_values = my_menu.values()
print(my_menu_values)
#dict_values(['Corn flakes', 'Falukorv och potatis', 'Köttfärssås och spagetti'])
for key, value in my_menu.items():
print(f'{key}:{value}')
favorit_språk = {
"Thomas" : ["Javascript", "C#", "HTML", "CSS"],
"Hans-Jones" : ["Python", "Java"],
"Hans-Edy" : ["C#", "Java", "ADA"]
}
for name, languages in favorit_språk.items():
print(f'{name.title()} favoritspråk är:')
for lang in languages:
print("\t" + lang)
users = {
"tbn": {
"firstname" : "Thomas",
"surname" : "Brunström",
"city" : "Borlänge"
},
"Hans": {
"firstname" : "Hans",
"surname" : "Jones",
"city" : "Borlänge"
}
}
for username, userinfo in users.items():
print(f'Username: {username}')
full_name = userinfo["firstname"] + " " + userinfo["surname"]
city = userinfo["city"]
print(f'Full name: {full_name} and location: {city}')
username = input("Ange ditt användarnamn")
password = input("Ange ditt lösenord")
print(f'Ditt användarnamn är: {username} och lösenord är: {password}')
age = input("Hur gammal är du? ")
nummer_age = int(age)
print(f'Ålder: {nummer_age} {nummer_age + 10}')
start = 0
while start <= 5:
print(f'Nuvarande nummer: {start}')
start += 1
print("Skriv något och programmet kommer repetera det du skrev.")
print("Skriv exit för att avsluta.")
message = ""
while message != "exit":
message = input()
if message == "hejsan":
break
else :
print(message)
from Dog import Dog
hund1 = Dog('Skrutten', 3)
print(hund1)
# Komma åt attribut
print(hund1.age)
print(hund1.name.title())
# Anropa metoder
hund1.sit()
hund1.roll_over()
# Skapa flera instanser
hund2 = Dog('Fido', 5)
hund3 = Dog('Aina', 6)
# en bilklass
from Car import Car, ElectricCar
my_car = Car('audi', 'A4', 2018)
print(my_car.get_descriptive_name())
my_car.read_odometer()
my_car.odometer_reading = 42
my_car.read_odometer()
my_car.update_odometer(55)
my_car.read_odometer()
my_tesla = ElectricCar('tesla', 'S', 2019)
print(my_tesla.get_descriptive_name())
my_tesla.battery.describe_battery()
my_tesla.battery.get_range()