This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grades = { | |
"Harry Potter": 70, | |
"Ron Weasley": 35, | |
"Hermione Granger": 99, | |
"Draco Malfoy": 23, | |
"Neville Longbottom": 98 | |
} | |
graded = [name for name, score in grades.items() if score >= 90] | |
print(graded) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in prime: | |
for y in range(2, i): | |
if (i % y) == 0: | |
print("{} is not a prime number, because {} is a divider of {}".format(i, y, i)) | |
break | |
if y == i -1: | |
print("{} is a prime number".format(i)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check_leap(year): | |
if year % 4 == 0 and year % 100 != 0: | |
leap = True | |
elif year % 4 == 0 and year % 100 == 0 and year % 400 == 0: | |
leap = True | |
elif year % 4 == 0 and year % 100 == 0 and year % 400 != 0: | |
leap = False | |
elif year % 4 != 0 : | |
leap = False | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
number = input() | |
first = number.split() | |
second = [int(c) for c in first] | |
third = np.array(second) | |
fourth = third.reshape(3,3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create a list | |
gryffindor = ['Harry Potter', 'Ron Weasley', 'Hermione Granger'] | |
gryffindor | |
#Output ['Harry Potter', 'Ron Weasley', 'Hermione Granger'] | |
# create another list | |
slytherin = ['Draco Malfoy'] | |
slytherin | |
#Output2 ['Draco Malfoy'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create a list of students | |
students = ['Harry Potter', 'Ron Weasley', 'Hermione Granger'] | |
# finding index | |
hermione = students.index('Hermione Granger') | |
hermione | |
#Output 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create a list | |
harry = ['H', 'a', 'r', 'y'] | |
harry | |
#Output ['H', 'a', 'r', 'y'] | |
# 'r' is inserted at index 2 (3th position) | |
harry.insert(2, 'r') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create a list of students | |
students = ['Harry Potter', 'Ron Weasley', 'Hermione Granger'] | |
students | |
#Output ['Harry Potter', 'Ron Weasley', 'Hermione Granger'] | |
# copy the list | |
gryffindor = students.copy() | |
gryffindor | |
#Output ['Harry Potter', 'Ron Weasley', 'Hermione Granger'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
numbers_unsorted = [102, 94, 5 ,7 , 32, 60, 48, 35] | |
numbers_unsorted | |
#Output [102, 94, 5, 7, 32, 60, 48, 35] | |
numbers_unsorted.sort() | |
print(numbers_unsorted) | |
#Output2 [5, 7, 32, 35, 48, 60, 94, 102] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create a list of students | |
students = ['Harry Potter', 'Ron Weasley', 'Hermione Granger'] | |
students | |
# Output ['Harry Potter', 'Ron Weasley', 'Hermione Granger'] | |
# To remove the element at index 2 | |
removed_element = students.pop(2) | |
removed_element | |
#Output2 'Hermione Granger' |
NewerOlder