Skip to content

Instantly share code, notes, and snippets.

View PythonRulz's full-sized avatar

Weaver PythonRulz

  • Oil and Gas
  • Texas, United States
View GitHub Profile
@PythonRulz
PythonRulz / main.py
Created November 30, 2022 13:54
Higher or Lower
import random
from replit import clear
from art import logo, vs
from game_data import data
#get random information from data script
def get_data():
'''
Gets a random dictionary entry from the game_data file and returns it
'''
@PythonRulz
PythonRulz / find_common_letters_in_two_strings.py
Created February 16, 2022 17:47
The program takes two strings and checks common letters in both the strings.
'''
Problem Description
The program takes two strings and checks common letters in both the strings.
Problem Solution
1. Enter two input strings and store it in separate variables.
2. Convert both of the strings into sets and find the common letters between both the sets.
3. Store the common letters in a list.
4. Use a for loop to print the letters of the list.
@PythonRulz
PythonRulz / count_vowels_using_set.py
Created February 16, 2022 17:39
The program takes a string and creates a dictionary with key as first character and value as words starting with that character.
'''
Problem Description
The program takes a string and creates a dictionary with key as first character and value as words starting with that character.
Problem Solution
1. Enter a string and store it in a variable.
2. Initialize a count variable to 0.
3. Create a set containing vowels.
4. Use a for loop to traverse through the letters in the string.
@PythonRulz
PythonRulz / create_dict_from_string.py
Last active February 16, 2022 16:37
The program takes a string and creates a dictionary with key as first character and value as words starting with that character.
'''
Problem Description
The program takes a string and creates a dictionary with key as first character and value as words starting with that character.
1. Enter a string and store it in a variable.
2. Declare an empty dictionary.
3. Split the string into words and store it in a list.
4. Using a for loop and if statement check if the word already present as a key in the dictionary.
5. If it is not present, initialize the letter of the word as the key and the word as the value and append it to a sublist created in the list.
@PythonRulz
PythonRulz / count_occurence_of_word_in_string_to_dict.py
Created February 14, 2022 20:39
The program takes a string and counts the frequency of words appearing in that string using a dictionary.
'''
Problem Description
The program takes a string and counts the frequency of words appearing in that string using a dictionary.
Problem Solution
1. Enter a string and store it in a variable.
2. Declare a list variable and initialize it to an empty list.
3. Split the string into words and store it in the list.
4. Count the frequency of each word and store it in another list.
@PythonRulz
PythonRulz / maP-list_dictionary.py
Last active February 14, 2022 20:13
The program takes two lists and maps two lists into a dictionary.
'''
Problem Description
The program takes two lists and maps two lists into a dictionary.
Problem Solution
1. Declare two empty lists and initialize them to an empty list.
3. Consider a for loop to accept values for the two lists.
4. Take the number of elements in the list and store it in a variable.
5. Accept the values into the list using another for loop and insert into the list.
@PythonRulz
PythonRulz / remove_key_from_dictionary.py
Created February 14, 2022 17:01
The program takes a dictionary and removes a given key from the dictionary.
'''
Problem Description
The program takes a dictionary and removes a given key from the dictionary.
Problem Solution
1. Declare and initialize a dictionary to have some key-value pairs.
2. Take a key from the user and store it in a variable.
3. Using an if statement and the in operator, check if the key is present in the dictionary.
4. If it is present, delete the key-value pair.
@PythonRulz
PythonRulz / multiply_valaues_of_dictionary.py
Created February 14, 2022 16:46
The program takes a dictionary and multiplies all the items in the dictionary.
'''
Problem Description
The program takes a dictionary and multiplies all the items in the dictionary.
Problem Solution
1. Declare and initialize a dictionary to have some key-value pairs.
2. Initialize a variable that should contain the total multiplied value to 1.
3. Use the for loop to traverse through the values of the dictionary.
4. Then multiply all the values in the dictionary against each other.
@PythonRulz
PythonRulz / print_sum_of_dictionary_values.py
Created February 14, 2022 16:20
The program takes a dictionary and prints the sum of all the items in the dictionary
'''
Problem Description
The program takes a dictionary and prints the sum of all the items in the dictionary.
Problem Solution
1. Declare and initialize a dictionary to have some key-value pairs.
2. Find the sum of all the values in the dictionary.
3. Print the total sum.
4. Exit.
@PythonRulz
PythonRulz / generate_dictionary_of_n_n*n.py
Created February 14, 2022 16:14
The program takes a number from the user and generates a dictionary that contains numbers (between 1 and n) in the form (x,x*x).
'''
Problem Description
The program takes a number from the user and generates a dictionary that contains numbers (between 1 and n) in the form (x,x*x).
Problem Solution
1. Take a number from the user and store it in a separate variable.
2. Declare a dictionary and using dictionary comprehension initialize it to values keeping the number between 1 to n as the key and the square of the number as their values.
3. Print the final dictionary.
4. Exit.