Skip to content

Instantly share code, notes, and snippets.

@Nickikku
Last active July 3, 2017 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nickikku/1f089d7ba9924feeeda133c8b7327e7c to your computer and use it in GitHub Desktop.
Save Nickikku/1f089d7ba9924feeeda133c8b7327e7c to your computer and use it in GitHub Desktop.
Simple_exercises_python
Created on Mon Jul 3 12:14:05 2017
@author: nickikku
"""
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
c = []
for i in a:
if i in b:
c.append(i)
print(c)
print("Creating a random list")
import random
d = []
e = []
for i in range(10):
d.append(random.randint(1,100))
print(d)
for i in d:
if i in b:
e.append(i)
print(e)
Created on Mon Jul 3 11:21:01 2017
@author: nickikku
"""
# What are the divisors of your input?
num = int(input("Please enter a number: "))
a = []
for i in range(2, 10):
if num % i == 0:
a.append(i)
print(a)
Created on Mon Jul 3 08:41:41 2017
@author: nickikku
"""
# Is there a "5" in the list?
print("This is part one!")
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
b = []
c = int(input("Enter a number: "))
for i in a:
if i < c:
b.append(i)
print(b)
print("number position wil appear if it is in list: " + str([i for i,x in enumerate(a) if x == c]))
print("This is part two!")
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
b = []
c = int(input("Enter a number: "))
for i in a:
if i < c:
i *= 2
b.append(i)
print(b)
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
print([i for i,x in enumerate(a)])
Created on Mon Jul 3 13:57:52 2017
@author: nickikku
"""
import random
a = []
for i in range(10):
a.append(random.randint(1,100))
print(a)
#Fast way
b =[i for i in a if i % 2 == 0]
print(b)
#Slow way
d = []
for i in a:
if i % 2 == 0:
d.append(i)
print(d)
Created on Sun Jul 2 23:30:04 2017
@author: nickikku
"""
#When will you be 100 of age?
name = input("what is your name?: ")
print("Your name is: " + name)
age = int(input("what is your age?: "))
print("Your age is: " + str(age))
new_age = str(2017 + (100 - age))
print(name + ", you will be 100 in " + new_age)
times = int(input("How many copies do you want to see of the previous message: "))
for i in range(times):
print(name + ", you will be 100 in " + new_age)
Created on Mon Jul 3 08:24:16 2017
@author: nickikku
"""
#odd or even
print("Do you wish to know if number is odd or even?")
number = int(input("Enter a number: "))
numstring = str(number)
if number % 4 == 0:
print("We've got a lucky " + numstring + "!")
elif number % 2 == 0:
print(numstring + " is an even number")
else:
print(numstring + " is an odd number")
print("Lets go to the second part!")
num = int(input("Enter the first number: "))
check = int(input("Enter the second number: "))
numstring = str(num / check)
if num % check == 0:
print("We've got an even number, " + numstring + "!")
else:
print(numstring + " is an odd number")
Created on Mon Jul 3 12:57:46 2017
@author: nickikku
"""
c = str(input("Please write something down: "))
print(c)
d = ""
for i in reversed(c):
d += i
print(d)
if c == d:
print("Thats a palindrome!")
else:
print("Think harder!")
print("Same principle for lists")
import random
e = []
f = []
for i in range(5):
e.append(random.randint(1,10))
print(e)
for i in reversed(e):
f.append(i)
print(f)
if e == f:
print("Unbelievable, you just had a lucky numeric palindrome!")
else:
print("Maybe the next time...")
import random
g = []
h = []
for i in range(5):
g.append(random.randint(1,10))
h.append(random.randint(1,10))
g.sort()
h.sort()
print(g)
print(h)
if e == f:
print("Nice!")
else:
print("There was a great chance I guess...")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment