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