Skip to content

Instantly share code, notes, and snippets.

View gncll's full-sized avatar

Gencay gncll

View GitHub Profile
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)
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))
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
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)
@gncll
gncll / extend
Last active August 10, 2022 08:50
# 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']
# create a list of students
students = ['Harry Potter', 'Ron Weasley', 'Hermione Granger']
# finding index
hermione = students.index('Hermione Granger')
hermione
#Output 2
# 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')
@gncll
gncll / copy
Last active August 10, 2022 08:51
# 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']
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]
@gncll
gncll / pop
Created August 10, 2022 08:15
# 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'