Showing posts with label beginners. Show all posts
Showing posts with label beginners. Show all posts

12/3/22

Advent of Code - Day 1


--- Day 1: Calorie Counting ---

Santa's reindeer typically eat regular reindeer food, but they need a lot of magical energy to deliver presents on Christmas. For that, their favorite snack is a special type of star fruit that only grows deep in the jungle. The Elves have brought you on their annual expedition to the grove where the fruit grows.

11/25/22

Introduction to JavaScript


METHODS OF RUNNING JAVASCRIPT
  • Using consoles on webpages
  • using node.js
VARIABLES AND CONSTANTS

There are two methods of getting variables, both of which have similar syntax.
the two methods are:
  • let
  • var (an older version)


 In order to declare constants(i.e., variables which cannot be changed), you make use of the 'const' function.

CONSOLE.LOG
'console.log()' is used to display(print) information onto the user interface.

DATA TYPES
A list of all the data types in JavaScript are:
  • strings
  • number(integers and floats)
  • big int: larger numbers
  • Boolean: true or false
  • undefined: a variable with unassigned data
  • null: an empty variable, not the same as undefined
  • symbol
  • object: a collection of information similar to dictionaries or sets.
JAVASCRIPT OPERATORS

  • ASSIGNMENT OPERATORS


  • ARITHMETIC OPERATORS


  • COMPARISON OPERATORS


  • LOGICAL OPERATORS


  • BITWISE OPERATORS
JAVASCRIPT COMMENTS
There are two main types of comments in JavaScript



11/22/22

In Python Program Range(4) Returns...


Hey, guys. Welcome to my series Answering Random Questions in Python programming.
So here we have 'in Python program return for returns.' 
Okay, so it varies. Oh, sorry. No, sorry, wrong answer. Otherwise arbitrary range, is it? 
I mean, we are all familiar with range in statistics and know its current or the data within a starting point and an ending point in python. If we don't, you can't. You can't. 
There are two, actually multiple ways.
Three probably. 
But the first way is to just declare range and declare the ending point as when you pass only one variable into it. And what happens is it starts from zero. For example, here we have range four. So it's going to create a list kind of numbers from zero and stopping at 'n minus one' actually to meet mathematical. 
So it's not going to stop at first. It's going to be zero one, two, three, four isn't going to be included in that range, but you can set your starting point where you have maybe wanted to range from 'two comma four'. 
So the starting point is going to be two and then three because it's engine four. So range just picks a starting point to the number before the ending point. Even starting point isn't giving, then automatically starts at zero. So if you have if you print out range four is going to just print range zero, comma four. But if you now loop it because we have created a data structure. So if you loop treats you now print this. If for example for I in range for print, I then will have zero 1 to 3. All right. Yeah.

11/19/22

When Is Python Programming Used


Hey, guys. Welcome to my series, Answering Questions related to Python. 
So today we're going to answer the question, "when is Python programming used?"  
Now there's like a long list, but whenever you hear Python, the first thing that usually comes to mind is web development, data analysis and visualization, machine learning, A.I, Automation. 
And people also use Python to develop what you can use in programming language to develop another programming language. Not advisable, but some people use Python to develop games. You can use Python to develop low functioning softwares, basic desktop apps and yeah.

11/18/22

Does python require prior coding experience ​


All right. Welcome to my "answering popular questions relating to Python" series. And today, we're going to be answering whether or not Python needs prior coding experience. 
Even though doubt benefits you more. You honestly don't need to have any coding experience to jump into Python. And python can be your very first language for you to enter into the programming field. It's very straightforward. It doesn't have a strict syntax like C++ and all that for you to like follow. Making errors at that beginner stage is very scarce.
 It is user friendly even once you start advancing, but as an introductory language, python is a very good option.

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!


Problem 2 - Cafe menu

 Write a program that first displays a simple cafe menu (see example below), asks the user to enter the number of a choice, and either prints the appropriate action OR prints an error message that their choice was not valid.


Example output:


1. Soup and salad


2. Pasta with meat sauce


3. Chef's special


Which number would you like to order? 2


One Pasta with meat sauce coming right up!


Another example output:


1. Soup and salad


2. Pasta with meat sauce


3. Chef's special


Which number would you like to order? 5


Sorry, that is not a valid choice

9/8/22

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


9/7/22

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


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.

Sum of Consecutive Numbers

 No one likes homework, but your math teacher has given you an assignment to find the sum of the first N numbers.

Let’s save some time by creating a program to do the calculation for you!

Take a number N as input and output the sum of all numbers from 1 to N (including N).

Sample Input

100

Sample Output

5050

Explanation: The sum of all numbers from 1 to 100 is equal to 5050.

9/6/22

Flip the string

 Reversing a string is a common task during coding interviews.

Given a string as input, output its reverse.

Sample Input

hello world

Sample Output

dlrow olleh

Let's go shopping

 You’re making a shopping cart program.

The shopping cart is declared as a list of prices, and you need to add functionality to apply a discount and output the total price.

Take the discount percentage as input, calculate and output the total price for the shopping cart.

9/5/22

Name please

 You need to take the first and last name of a person as input and output the initials (first letters of the first and last name).

Sample Input

James

Smith

Sample Output

J.S.

Blog Archive