Showing posts with label projects. Show all posts
Showing posts with label projects. Show all posts

11/24/22

Where To Learn Python Programming For Free


Hi, guys. Welcome back to answering random questions on the Internet relating to Python programming. And yes, I know I have given this series more to name, but you know, we all know what we're doing here. 
So today we have "where to learn python programming for free" , so you can learn Python programming for free everywhere. It just depends on what level of programming you are at first and you know what you want to use. 
For example, if you prefer using blogs I'd advise programiz.
If you are on YouTube there is freecodecamp there is coding with mosh and there is me
So yeah, you can also go on TikTok or do programming on TikTok, it's usually snippets. It's not going to be detailed. 
You can go for courses like CS50, it's free. That's Harvard Computer Science, about introduction to programming using Python? It's free. The lecturer, I think. What's his name again? David. And he's a very good dude. He explains things very well. He was doing it was his course. I used to learn C or C++, I can't remember.

11/9/22

check data type for all elements in a list

For more codes click here 

#check data type for all elements in a list


a = [1,"pease", 4, "dog"]


for i in a:

    if isinstance(i, int):

        print(f"{i} is an integer")

    elif isinstance(i, str):

        print(f"{i} is a string")

    else:

        pass


10/16/22

BMI Calculator in python

A GUI application that takes user inputs to output their BMI

If you are not confident with python click here

For full source code Click here

10/15/22

Acronyms.py

A project to help create acronyms to any sentence passed into the software.

10/1/22

Simple calculator using python and tkinter

 from re import sub

from tkinter import *


#creating a window
root =  Tk()

#decale the default variable
calc = ""

#definig the function
def addi():
    global calc
    calc += "+"
    pop['text'] = calc

def subi():
    global calc
    calc += "-"
    pop['text'] = calc

def divi():
    global calc
    calc += "/"
    pop['text'] = calc

def multipl():
    global calc
    calc += "*"
    pop['text'] = calc

def ze():
    global calc
    calc += "0"
    pop['text'] = calc

def on():
    global calc
    calc += "1"
    pop['text'] = calc

def tw():
    global calc
    calc += "2"
    pop['text'] = calc

def th():
    global calc
    calc += "3"
    pop['text'] = calc

def fo():
    global calc
    calc += "4"
    pop['text'] = calc

def fi():
    global calc
    calc += "5"
    pop['text'] = calc

def si():
    global calc
    calc += "6"
    pop['text'] = calc

def se():
    global calc
    calc += "7"
    pop['text'] = calc

def ei():
    global calc
    calc += "8"
    pop['text'] = calc

def ni():
    global calc
    calc += "9"
    pop['text'] = calc

def decii():
    global calc
    calc += "."
    pop["text"] = calc

def evali():
    global calc
    try:
        calc = eval(calc)
        pop["text"] = calc
        calc = ""
    except:
        pop['text'] = "AN ERROR OCCURRED"
        calc = ""

def cleari():
    global calc
    calc = ""
    pop["text"] = calc



#naming the window
root.title("A SIMPLE CALCULATOR")

#label and entry field
m = Label(root, text="CALCULATOR", font=(25))
pop = Label(root, text='', font=(50))

#operators box
adding = Button(root, text="+",height=2, width=5, command=addi)
subtracting = Button(root, text="-",height=2, width=5, command=subi)
dividing = Button(root, text="/",height=2, width=5, command=divi)
multiplying = Button(root, text="*",height=2, width=5, command=multipl)
equating = Button(root, text="=", height=10, width=13, command=evali)

#numbers
nine = Button(root, text="9", height=2, width=5, command=ni)
eight = Button(root, text="8", height=2, width=5, command=ei)
seven = Button(root, text="7", height=2, width=5, command=se)
six = Button(root, text="6", height=2, width=5, command=si)
five = Button(root, text="5", height=2, width=5, command=fi)
four = Button(root, text="4", height=2, width=5, command=fo)
three = Button(root, text="3", height=2, width=5, command=th)
two = Button(root, text="2", height=2, width=5, command=tw)
one = Button(root, text="1", height=2, width=5, command=on)
zero = Button(root, text="0", height=2, width=5, command=ze)
ccc = Button(root, text="C", height=2, width=5, command=cleari)
deci = Button(root, text=".", height=2, width=5, command=decii)

#placing on screen
m.place(x=190, y=0)
pop.place(x=100, y=30)

#placiing operators
adding.place(x=100, y=60)
subtracting.place(x=150, y=60)
dividing.place(x=200, y=60)
multiplying.place(x=250, y=60)
equating.place(x=300, y=60)

#placing digits
nine.place(x=100, y=100)
eight.place(x=150, y=100)
seven.place(x=200, y=100)
six.place(x=250, y=100)
five.place(x=100, y=140)
four.place(x=150, y=140)
three.place(x=200, y=140)
two.place(x=250, y=140)
ccc.place(x=100, y=180)
one.place(x=150, y=180)
zero.place(x=200, y=180)
deci.place(x=250, y=180)

root.resizable(False, False)
root.geometry("500x500")



root.mainloop()


9/11/22

Problem 2 - The game of Nims / Stones

 In this game, two players sit in front of a pile of 100 stones. They take turns, each removing between 1 and 5 stones (assuming there are at least 5 stones left in the pile). The person who removes the last stone(s) wins.


Write a program to play this game. This may seem tricky, so break it down into parts. Like many programs, we have to use nested loops (one loop inside another).


In the outermost loop, we want to keep playing until we are out of stones.


Inside that, we want to keep alternating players. You have the option of either writing two blocks of code, or keeping a variable that tracks the current player. The second way is slightly trickier since we haven't learned lists yet, but it's definitely do-able!


Finally, we might want to have an innermost loop that checks if the user's input is valid. Is it a number? Is it a valid number (e.g. between 1 and 5)? Are there enough stones in the pile to take off this many? If any of these answers are no, we should tell the user and re-ask them the question.


So, the basic outline of the program should be something like this:


TOTAL = 100


MAX = 5


pile = TOTAL # all stones are in the pile to start


while [pile is not empty]:


while [player 1's answer is not valid]:


[ask player 1]


[check player 1's input... is it valid?]


[same as above for player 2]


Note how the important numbers 100 and 5 are stored in a single variable at the top. This is good practice -- it allows you to easily change the constants of a program. For example, for testing, you may want to start with only 15 or 20 stones.


Be careful with the validity checks. Specifically, we want to keep asking player 1 for their choice as long as their answer is not valid, BUT we want to make sure we ask them at least ONCE. So, for example, we will want to keep a variable that tracks whether their answer is valid, and set it to False initially.


When you're finished, test each other's programs by playing them!


Registration System

 You are making a registration form for a website.

The form has a name field, which should be more than 3 characters long.

Any name that has less than 4 characters is invalid.

Complete the code to take the name as input, and raise an exception if the name is invalid, outputting "Invalid Name". Output "Account Created" if the name is valid.

Sample Input

abc

Sample Output

Invalid Name

Shooting Game

 You are creating a shooting game!

The game has two types of enemies, aliens and monsters. You shoot the aliens using your laser, and monsters using your gun.

Each hit decreases the lives of the enemies by 1.

The given code declares a generic Enemy class, as well as the Alien and Monster classes, with their corresponding lives count.

It also defines the hit() method for the Enemy class.

You need to do the following to complete the program:

1. Inherit the Alien and Monster classes from the Enemy class.

2. Complete the while loop that continuously takes the weapon of choice from user input and call the corresponding object's hit() method.

Sample Input

laser

laser

gun

exit

Sample Output

Alien has 4 lives

Alien has 3 lives

Monster has 2 lives

9/8/22

Letter Counter

 Given a string as input, you need to output how many times each letter appears in the string.

You decide to store the data in a dictionary, with the letters as the keys, and the corresponding counts as the values.

Create a program to take a string as input and output a dictionary, which represents the letter count.

Sample Input

hello

Sample Output

{'h': 1, 'e': 1, 'l': 2, 'o': 1}

Fruit Bowl

 You have a bowl on your counter with an even number of pieces of fruit in it. Half of them are bananas, and the other half are apples. You need 3 apples to make a pie.

Task

Your task is to evaluate the total number of pies that you can make with the apples that are in your bowl given to total amount of fruit in the bowl.

Input Format

An integer that represents the total amount of fruit in the bowl.

Output Format

An integer representing the total number of whole apple pies that you can make.

Sample Input

26

Sample Output

4

Popsicles

 You have a box of popsicles and you want to give them all away to a group of brothers and sisters. If you have enough left in the box to give them each an even amount you should go for it! If not, they will fight over them, and you should eat them yourself later.

Task

Given the number of siblings that you are giving popsicles to, determine if you can give them each an even amount or if you shouldn't mention the popsicles at all.

Input Format

Two integer values, the first one represents the number of siblings, and the second one represents the number of popsicles that you have left in the box.

Output Format

A string that says 'give away' if you are giving them away, or 'eat them yourself' if you will be eating them yourself.

Sample Input

3 9

Sample Output

give away


Contact Search

 You are given a list of contacts, where each contact is represented by a tuple, with the name and age of the contact.

Complete the program to get a string as input, search for the name in the list of contacts and output the age of the contact in the format presented below:

Sample Input

John

Sample Output

John is 31

9/7/22

Car data

 You are working at a car dealership and store the car data in a dictionary:

car = {

    'brand': 'BMW',

    'year': 2018,

    'color': 'red'

}

Your program needs to take the key as input and output the corresponding value.

Sample Input

year

Sample Output

2018

Search Engine

 You’re working on a search engine. Watch your back Google!

The given code takes a text and a word as input and passes them to a function called search().

The search() function should return "Word found" if the word is present in the text, or "Word not found", if it’s not.


Sample Input

"This is awesome"

"awesome"

Sample Output

Word found


How many letters

 Write a function that takes a string and a letter as its arguments and returns the count of the letter in the string.

Sample Input

hello, how are you?

o

Sample Output

3

Explanation: The letter o appears 3 times in the given text.

From feet to inches

 You need to make a function that converts a foot value to inches.

1 foot has 12 inches.

Define a convert() function, that takes the foot value as argument and outputs the inches value.

Shouting text

 Your friend is sending you a text message, however his caps lock is broken and the whole message is in uppercase.

Noone likes being shouted at, plus uppercase text is hard to read, so you decide to write a program to convert the text to lowercase and output it.

Take a string as input and output it in lowercase.

Analyze to realize

 You’re analyzing a data set and need to remove the outliers (the smallest and largest values.

The data is stored in a list).

Complete the code to remove the smallest and largest elements from the list and output the sum of the remaining numbers.

9/6/22

Nearest Bathroom

 A group of buildings have restrooms on every 5th floor.

For example, a building with 12 floors has restrooms on the 5th and 10th floors.

Create a program that takes the total number of floors as input and outputs the floors that have restrooms.

Sample Input

23

Sample Output

5

10

15

20

Just say it

 You’re making a voice recognition system.

The supported commands are stored in a list.

Complete the program to take a command as input, check if it’s supported and output "OK", if it is, and "Not supported", if not.

Sample Input

Lights Off

Sample Output

OK


Blog Archive