5 Python Projects for Beginners
01 — Name Builder
Creates fake names by making random selections from the specified name and last name lists.
Modules used: random
123456789 import random2.3.def generate_name():4. first_names = ["Albert", "Charles", "Nicolas", "Michael", "Anders", "Isaac", "Stephen", "Marie", "Richard"]5. last_names = ["Einstein", "Darwin", "Copernicus", "Faraday", "Celsius", "Newton", "Hawking", "Curie","Dawkins"]6. return " ".format(random.choice(first_names), random.choice(last_names))7.8.for i in range(5):9. print(generate_name())
02- Temperature Converter
According to the selection (½) the temperature value entered in degrees Celsius to Fahrenheit or vice versa, the program turns.
12345678910111213141516171819 print("-" * 30)2.print("1- Celsius to fahrenheit")3.print("2- Fahrenheit to celsius")4.print("-" * 30)5.6.choice = raw_input("Your choice (1/2): ")7.8.if choice == "1":9. print("\n# Celsius to Fahrenheit")10. celsius = float(raw_input("Degree to convert: "))11. fahrenheit = (celsius * 1.8) + 3212. print(" degree celsius is equal to degree fahrenheit.".format(celsius, fahrenheit))13.elif choice == "2":14. print("\n# Fahrenheit to Celsius")15. fahrenheit = float(raw_input("Degree to convert: "))16. celsius = (fahrenheit - 32) / 1.817. print(" degree fahrenheit is equal to degree celsius.".format(fahrenheit, celsius))18.else:19. print("Congratulations! You hacked the super-program.")
03 — how many seconds have you lived?
Day from user.month.the date of birth in the year format is calculated and the difference of today is written to the screen in seconds.
Modules used: datetime
123456 from datetime import *2.3.birth = datetime.strptime(raw_input("Your birth date (d.m.Y): "), "%d.%m.%Y")4.age = datetime.now() - birth5.6.print("You survived seconds.".format(age.total_seconds()))
04-Simple Encryption / Analysis
The ascii code value of each character in the entered text is incremented (I) as much as the value received from the user. To solve the encrypted text is also reduced to the opposite.
1234567891011121314151617 def encrypt(text, value, output=""):2. for char in text:3. output = "".format(output, chr(ord(char) + value))4. return output5.6.def decrypt(text, value, output=""):7. for char in text:8. output = "".format(output, chr(ord(char) - value))9. return output10.11.i = int(raw_input("Increment value: "))12.13.text = raw_input("Type your text: ")14.print("Encrypted text: ".format(encrypt(text, i)))15.16.text = raw_input("\nType for decrypt: ")17.print("Decrypted text: ".format(decrypt(text, i)))
05 — FizzBuzz
The value from the user prints the number itself for the three-fold in an array of length, “Fizz” for the five-fold, “buzz” for the five-fold, “fizzbuzz” for both five-folds, and “fizbuzz” for the three-fold, if not all.
1234567891011121314 def fizzbuzz(n):2. if n % 3 == 0 and n % 5 == 0:3. return "FizzBuzz"4. elif n % 3 == 0:5. return "Fizz"6. elif n % 5 == 0:7. return "Buzz"8. else:9. return str(n)10.11.length = int(raw_input("Length of array: "))12.13.for i in range(1, length):14. print(fizzbuzz(i))
Thanks for reading, if you have a any issue please contact.