Python Source Projects for Beginners
Python Source Projects
In this article, I share python open source projects that can provide convenience for users who have just started Python programming language. If there is any problem about the open source projects I will give, please specify them as a comment. I will try to help you as much as I can and help you develop yourself in Python programming language.
Python Password Generator
The length and level values are obtained from the user. Characters that can be selected include letters, two-thirds numbers and special characters. Then these characters are randomly taken and rotated as long as the specified length.
Modules used: random, string
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import random import string def generate_password(length, level, output=[]): chars = string.ascii_letters if level > 1: chars = "{}{}".format(chars, string.digits) if level > 2: chars = "{}{}".format(chars, string.punctuation) for i in range(length): output.append(random.choice(chars)) return "".join(output) print(("-" * 30) + "\n Password Generator\n" + ("-" * 30)) password_length = int(raw_input("Length: ")) password_level = int(raw_input("Level: ")) password = generate_password(password_length, password_level) print("\nYour password is: {}".format(password)) |
Python Haiku Generator
Words[0], words[1], and so on … I was just doing it. Then I called to see if there was any shorter, and I found out that when words did, the elements settled in the middle.
Modules used: random
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | from random import choice words = [ choice(["Enchanting", "Amazing", "Colourful", "Delightful", "Delicate"]), choice(["visions", "distance", "conscience", "process", "chaos"]), choice(["superstitious", "contrasting", "graceful", "inviting", "contradicting", "overwhelming"]), choice(["true", "dark", "cold", "warm", "great"]), choice(["scenery","season", "colours","lights","Spring","Winter","Summer","Autumn"]), choice(["undeniable", "beautiful", "irreplaceable", "unbelievable", "irrevocable"]), choice(["inspiration", "imagination", "wisdom", "thoughts"]) ] print(("-" * 30) + "\nHaiku Generator\n" + ("-" * 30)) print("{} {},\n{} {} {},\n{} {}.".format(*words)) |
Python Eight Magical Balls
He gives random answers like toys that randomly bring the answers in the liquid BI triangular prism in the ball.
Modules: random
1 2 3 4 5 6 | from random import choice answers = ["It is certain", "Outlook good", "You may rely on it", "Ask again later", "Concentrate and ask again", "Reply hazy, try again", "My reply is no", "My sources say no"] raw_input("Ask your question to magic eight ball: ") print("Answer: {}".format(choice(answers))) |
Python Reverse Text
It reverses the text entered by the user and writes it to the screen.
1 2 3 4 5 6 7 8 9 | def reverse(value, output=[]): #range(start, stop, step) for i in range(len(value) - 1, -1, -1): output.append(value[i]) return "".join(output) text = raw_input("What's up: ") print("Your reversed text is: {}".format(reverse(text))) |
Python Word Count in Text
The entered text is broken into spaces and is checked to see if each part is completely made up of punctuation marks. Appropriate words are counted and the result is written on the screen.
Modules used: string
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import string def is_word(text): for char in text: if not char in string.punctuation: return True return False def word_count(value, output = 0): potential_words = value.split(" ") for word in potential_words: if is_word(word): output += 1 return output text = raw_input("Tell something: ") print("Total words: {}".format(word_count(text))) |
Python Translating The Entered Number into Binary
The decimal number of the user enters into the binary system. In addition to the function we wrote, I added two other ways Python provided to us.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | decimal = int(raw_input("Number in decimal format: ")) def binary(n): output = "" while n > 0: output = "{}{}".format(n % 2, output) n = n // 2 return output # our method print(binary(decimal)) # another way print(bin(decimal)[2:]) # yet another way print("{0:b}".format(decimal)) |
Python Factoring Accounting
The face (or “n”) calculates factoring.
1 2 3 4 5 6 7 | def factorial(n, fact=1): for i in range(1, n + 1): fact *= i return fact print("Factorial of 100: {}".format(factorial(100))) |
Python Christmas Tree In Console
Draws a Christmas tree at the given height.
1 2 3 4 5 6 7 | height = int(raw_input("Height of Christmas Tree: ")) for i in range(int(height * 0.7)): print( (" " * (height - ( i // 2))) + ("*" * i)) for i in range(int(height * 0.7), height): print((" " * (height - 1)) + "||") |
Python Sort Algorithm
Using the bubble sort algorithm, sorts the array from small to large.
1 2 3 4 5 6 7 8 9 10 11 12 13 | def bubble_sort(array): for i in range(1, len(array)): for j in range(len(array) - i): if array[j] > array[j + 1]: temp = array[j] array[j] = array[j + 1] array[j + 1] = temp return array numbers = [1, 12, 2, 5, 6, 1, 8, 55, 8, 8, 2, 17] print("Sorted array: {}".format(bubble_sort(numbers))) |
Python Calculating The Writing Speed
The user is asked to enter a text, the first time the difference between the time after the writing is written to the screen in seconds. The user is said to have typed how many numbers per second.
Modules used: datetime
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | from datetime import * before = datetime.now() text = "Say hello to my little friend." print("Please type: {}".format(text)) if text == raw_input(": "): after = datetime.now() speed = after - before seconds = speed.total_seconds() letter_per_second = round(len(text) / seconds, 1) print("You won!") print("Your score is: {} seconds.".format(seconds)) print("{} letters per second.".format(letter_per_second)) else: print("You failed.") |
Доставка цветов в селе Караидель dostavka-byketov.ru. https://www.kalogroup.com.au/