Skip to content

Instantly share code, notes, and snippets.

View cjshaw1976's full-sized avatar
:atom:
Always learning & developing.

Chris Shaw cjshaw1976

:atom:
Always learning & developing.
View GitHub Profile
from datetime import date
name = input("What is your name? ")
age = int(input("What is your age? "))
copies = int(input("How many times do you want to see our message? "))
year_100 = 100 - age + date.today().year
message = "Hello {}. You will be 100 in {}.\n".format(name, year_100)
print(copies * message)
def answer(x):
result = 1
while x > 0:
result += (7 ** x)
x -= 1
return result
'''
Minion hierarchy
================
number = int(input("Enter an integer number: "))
if number % 2 == 0:
if number % 4 ==0:
print("Your number {} is an even number and is also divisable by 4.".format(number))
else:
print("Your number {} is an even number.".format(number))
else:
print("Your number {} is an odd number.".format(number))
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
number=int(input("Give us a number> "))
x = []
for element in a:
if element < number:
x.append(element)
print(x)
number = int(input("Enter a number to calculate its divisors: "))
divisors = []
for test in range(2, number):
if number % test == 0:
divisors.append(test)
print(divisors)
'''
05.py: Exercise 05 from practicepython.org.
Take two lists and write a program that returns a list that contains only the elements that are common between the lists (without duplicates).
'''
__author__ = "Christopher J Shaw"
import random
list1=[]
list2=[]
'''
06.py: Ask the user for a string and print out whether this string is a palindrome or not. (A palindrome is a string that reads the same forwards and backwards.)
'''
___author___ = "Christopher J Shaw"
user_input = input("Enter a string to test if it is a palindrome: ").lower()
if user_input == user_input[::-1]:
print("Yes {} is a palindrome".format(user_input))
else:
'''
07.py: Write one line of Python that takes this list a and makes a new list that has only the even elements of this list in it.
'''
____author___="Christopher J Shaw"
nums = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
even = [num for num in nums if not num % 2]
print(even)
"""
Make a two-player Rock-Paper-Scissors game.
"""
___author___ = "Christopher J Shaw"
import os
def cls():
os.system('cls' if os.name=='nt' else 'clear')
"""
Generate a random number between 1 and 9 (including 1 and 9). Ask the user to guess the number, then tell them whether they guessed too low, too high, or exactly right.
Keep going till the user types exit. Keep track of number of attempts
"""
___author___ = "Christopher J Shaw"
import random
number = random.randint(1, 9)