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
'''
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:
'''
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=[]
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)
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 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))
def answer(x):
result = 1
while x > 0:
result += (7 ** x)
x -= 1
return result
'''
Minion hierarchy
================
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)