Skip to content

Latest commit

 

History

History
102 lines (77 loc) · 4.73 KB

File metadata and controls

102 lines (77 loc) · 4.73 KB

Python script ideas

This file contains Python scripting ideas.

If you are stuck, there is usually a finished example in the python/ folder to look at.

Use the python guide to learn about concepts used in these exercises

Level 1 (Start here)

  • 18+ checker by age

    • Provide an age
    • Print "You are 18 or above" or "You are underage"
    • HintUse if, < or > and else
  • Calculator

    • Sum (+) 2 user-defined numbers
    • HintUse int(input()) to get two numbers from the user
    • Extra: Let the user decide between operands +, -, *, or /
      • HintUse input() so the user can choose an operand, then do something like:
        if operand == "+":
        result = first_num + second_num
  • Palindrome checker

    • Definition: A word that stays the same when read backwards. E.g. 'racecar' or 'madam'

Level 2

  • User math trainer

    • Generate random math problem (+, - or *)
    • User calculates and enters his answer
    • Tell the user whether his answer is correct
    • Tip: Avoid / for now
  • Random password generator

    • Generate a string of random characters. E.g. wgH^@Q60bIr1YGw3
    • Use import random
    • HintDefine a list of characters: characters = list("abcdefghijklmnopqrstuvwxyz!@#$%^&*()_+") and use random.choice(characters) to get a random character
  • Random number guessing game

    • "Guess a number:", "Too high!", "Too low!", "You win!"
    • HintUse < and >

Level 3

  • Prime number checker

    • Provide any number
    • Rule for Prime Numbers: A prime number can only be divided by 1 and itself
    • Hint 1Use the modulo operator % (x % y equals 0 if x is divisible by y, meaning there is no remainder)
    • Hint 2Assume it's a prime, then try to prove that it's not
  • Collatz conjecture

    • Provide a starting number
    • Rules
      • If even, divide by 2
      • If odd, multiply by 3 and add 1
    • Stop when you reach 1
  • Fibonacci sequence

    • Starting numbers are: 0, 1
    • 0 1 1 2 3 5 8 13 21 34 55 (Next number is the sum of the last two)
    • HintUse a "temp" variable

Level 4

  • Caesar cipher encoder

    • Set an alphabet list: alphabet = list("abcdefghijklmnopqrstuvwxyz")
    • Provide a starting word
    • Provide a number
    • Rule of Caesar Cipher: All letters in the word are "shifted" in the alphabet based on the number. abc with number 1 becomes bcd.
    • Extra: Make sure if you shift e.g. z by 2, it wraps back to the start and returns b.
      • HintUse the modulo operator % with the alphabet length len(alphabet)
  • Anagram Finder

    • Make a wordlist with a bunch of words (E.g.: "listen", "silent", "dormitory", "dirty room", "debit card", "bad credit")
    • Tip: Do Palindrome checker first!
    • Definition: "a word, phrase, or name formed by rearranging the letters of another, such as spar, formed from rasp."
    • HintUse sorted(). Two words are anagrams if sorted(word_one) equals sorted(word_two).

Level 5

  • Hangman

    • A random word is chosen. The user doesn't know the word. The user guesses one letter at a time.
    • Reveal all occurrences of a letter after it has been guessed.
      Let's say the word is banana: ______ -> user guesses a -> _a_a_a and so on.
    • The user wins if all letters have been revealed.
      • HintCheck if there are no `_`s (empty fields) left
    • Extra: Give the user 5 "hearts" and make him lose if he has no hearts left
  • Tic Tac Toe

    • Create a playing board (array with 9 slots)
    • Let user pick a position to play
    • Alternate between player X and player O
    • Display the board after every move
    • Win condition: 3 in a row (horizontally, vertically, on the diagonal)

Level 6 (Advanced)