0% found this document useful (0 votes)
2 views10 pages

Program A 22

The document provides a comprehensive overview of basic programming concepts, including data types (string, integer, float, boolean), user input, typecasting, and control structures (if statements, loops). It also includes examples of practical applications such as a calculator, weight converter, and simple games like Madlibs. Additionally, the document touches on Java programming basics, highlighting logical operators and loops.

Uploaded by

allanchichava
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views10 pages

Program A 22

The document provides a comprehensive overview of basic programming concepts, including data types (string, integer, float, boolean), user input, typecasting, and control structures (if statements, loops). It also includes examples of practical applications such as a calculator, weight converter, and simple games like Madlibs. Additionally, the document touches on Java programming basics, highlighting logical operators and loops.

Uploaded by

allanchichava
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

#string= a series of text, can include numbers.

first_name= "Bro"
food = "Pizza"
email = "[email protected]"
print(f"hello {first_name}")
print (f"you like {food}")
print (f"your email is: {email}")

#integer = a whole number


#we don`t use quotes " " in integers
age = 19
quantity = 3
number_of_students = 26
print (f"you are {age} years old")
print (f"you are buying {quantity} apples")
print (f"Your class has {number_of_students} students")

# Float
price = 10.99
gpa = 3.2
distance = 2.8
print (f"A electric guitar is {price}")
print (f"Your gpa is: {gpa}")
print (f"you ran {distance} km")

# Boolean ( can either be true or false)


for_sale = True
is_online = False
is_student = True

if is_student:
print ("You are a student")
else:
print ("You are not a student")

if for_sale:
print ("That item is for sale")
else:
print ("That item is not for sale")

if not is_online:
print("You are not online")
else:
print("You are online")

Typecasting
#Typecasting= the process of converting a variable from one data type to
another
name = "vas"
age = 22
gpa = 3.2
is_student = False

print (type(is_student))

gpa = int (gpa)


print(gpa)

name = bool (name)


print (name)

age = float (age)


age = print(age)

age = str (age)


print (type(age))

User input
# input() = A function that prompts the useer to enter data
# Returns the entered data as a string
name =input("What is your name?:")
age =input ("How old are you?:")
birthday = input ("When is your birthday?:")

age = int (age)


age = age+1

print (f"Hello {name}!")


print ("Happy Birthday")
print (f"You are {age} years old!")

name =input("What is your name?:")


age =int (input("How old are you?:"))

age = age+1

print (f"Hello {name}!")


print ("Happy Birthday")
print (f"You are {age} years old!")
Exercises 1 rectangle area calc
# Exercise 1 Rectangle area calc
#length = float(input("Enter the length:"))
#width = float(input("Enter the width:"))
#area =length * width
#print (f"The area is {area} metres" )

# Exercise 1 Rectangle area calc


# Exercise 1 Rectangle area calc
#length = float(input("Enter the length:"))
#width = float(input("Enter the width:"))
#area =length * width
#print (f"The area is {area} metres" )

# Exercise 2 Shopping cart program


item = input ("What item would you like to buy?: ")
price = float (input("What is the price?: "))
quantity = int(input("How many would you like?:"))
total= price * quantity

print (f"You have bought {quantity} {item}/s")


print (f"Your total is {total}")

Madlibs games
# word game where you create a story
# by filling in blanks with random words

adjective1 = input ("Enter an adjective (description):")


noun1= input ("Enter a noun (person, place, object):")
adjective2 = input ("Enter an adjective (description):")
verb1 = input ("Enter a verb ending with 'ing'")
adjective3 = input ("Enter an adjective (description):")

print (f"Today I went to a {adjective1} zoo")


print(f"In an exhibit, I saw a {noun1}")
print (f"{noun1} was {adjective2} and {verb1} ")
print (f"I was {adjective3}!")
Math operators
# (**) = expoente.
#friends = 5
#friends **= 3
#friends-= 3
#friends *=4

# abs = absolute value.

#x = 3.14
#y = 4
#z = 5

#result = round (x)


#result = abs (y)
#result = pow ( 2,3) # or ( 2**3)
#result = max (x, y, z)
#result = min ( x, y, z)

import math
#print (math.pi)
#print (math.e)

#result = math.sqrt(x)
#x = 25
#print (result)

# ceil = always rounds up


# floor = always rounds down

x = 9.1
result = math.ceil (x)
print (result)

y = 9.9
result = math.floor (y)
print (result)

import math

radius = float(input ("Enter the radius o a circle:"))


circumference = 2 * math.pi * radius
print (f"The circumference is: { circumference}")

import math
adjacent = float (input("Enter the adjacent:"))
opposite = float (input ("Enter the opposite:"))
hypotenuses = math.sqrt ( (adjacent **2) + (opposite**2))

print (f"The hypotenuses of the triangle is {hypotenuses}")


IF STATEMENTS

# if = Do some code only if some condition is True


# Else: do something else
# elif = else if

#age = int(input("Enter your age:"))


#if age >= 20:
# print ("You are now signed up!")

#elif age < 0:


# print ("You haven't been born yet")

#else:
# print ("You must be 18 or older to sign up!")

#response = input("Would you like to order food? (Yes/No):")

# if response == "Yes":
# print ("Choose your food!")

# else:
#print ("You may leave!")

#name = input("Enter your name: ")


#if name == "":
# print ("You did not enter your name")

#else:
# print (f"Hello {name}!")

Calculator
operator = input("Enter an operator (+ - * /): ")
number1 = float(input("Enter the first number: "))
number2 = float(input("Enter the second number: "))

if operator == "+":
result = number1 + number2
print (result)
elif operator== "-":
result = number1 - number2
print(result)
elif operator == "*":
result = number1 * number2
print(result)
elif operator == "/":
result = number1 / number2
print(result)

Weight converter
weight = float(input("Enter your weight:"))
unit = input ( "Kilograms or pounds? (Kg or Lb):")

if unit == "K":
weight = weight * 2.205
unit = "Lbs."
elif unit == "L":
weight = weight / 2.205
unit = "Kgs."

else:
print (f"The {unit} you introduced is not valid")

print (f"Your weight is {weight} {unit}")

unit = input ("Is this temperature in Celsius or in Fahrenheit? (C/F):")


temp = float(input ("Enter the temperature:"))

if unit == "C":
temp = ((9 * temp) / 5 + 32)
print (f" The temperature in Fahrenheit is {temp} {unit}")
elif unit == "F":

else:
print (f"The{unit} is an invalid unit of measurement")

# logical operators = evaluate multiple conditions ( or, and, not)


# or = at least one of the statements must be true
# and = both of them must be true
# not = inverts the condition (not true, not false)
# And logical operator
else:
print ("You can`t go swimming")

# conditional expression = A one line shortcut to the if-statements


# Print or assign one or two values based on a
condition
# X if condition else Y

num = 10
a = 9
b = 7
age = 2
temperature = 26
user_role = "admin"

# print ( "positive" if num > 0 else "negative")


#result = "Even" if num % 2==0 else "Odd"
#print (result)

#max_numb = a if a > b else b


#print (max_numb)

#min_numb = a if a < b else b


#print (min_numb)

#Status = "adult" if age >= 20 else "Not adult"


#print (Status)

#Weather = "Hot" if temperature >=30 else "Fresh"


#print (Weather)

acess_level = "Full acess" if user_role== "admin" else "Limited"


print(acess_level)

Java
import java.util.Scanner;
package dia1b;

public class Operators2 {


public static void main(String[] args) {
// TODO Auto-generated method stub
//&& = (And) both conditions must be true
//|| = (OR) one of the conditions must be true
// || = (not) reverses boolean value of condition

Scanner scanner = new Scanner (System.in);

System.out.println("You are playing a game! Press q or Q to quit");


String response = scanner.next();

if (response.equals("q") || response.equals("Q")) {
System.out.println("You quit the game");
}
else {
System.out.println("You are still playing the game");
}

package primeirodia;

public class LogicalOperators {

public static void main(String[] args) {


// TODO Auto-generated method stub

//&& = (And) both conditions must be true


//|| = (OR) one of the conditions must be true
// || = (not) reverses boolean value of condition

int temp = 30;


if (temp>=30) {
System.out.println("It is hot outside");
}
else if (temp>= 20 && temp<=30) {
System.out.println("It is warm outside");
}
else {
System.out.println("It is cold outside");
}
}
}

While loop
package aulas;
import java.util.Scanner;
public class JavaEstudo {

public static void main(String[] args) {

// while loop = executed a block of code as long as a it´s


condition remains true

Scanner scanner = new Scanner(System.in);


String name = "";

while(name.isBlank()) {
System.out.println("Enter your name: ");
name = scanner.nextLine();
}
System.out.println("Hello, "+name);
}

For loops
package aulas;

public class JavaEstudo {

public static void main(String[] args) {

// for loop = executes a block of code a limited amount of times

for (int i=10; i>=1; i--) {

System.out.println(i);
}

System.out.println("Happy new year");


}
}
Nested loops
Se ( aP> aC)-> Se ( aP > aB)-> msg<- “ O artigo mais solicitado foi a pulseira”

->Se ( aB> aP) -> msg<- “O artigo mais solicitado foi a Bolsa”

Se ( aC> aP)-> Se ( aC > aB)-> msg<- “ O artigo mais solicitado foi o colar”

->Se ( aB> aC) -> msg<- “O artigo mais solicitado foi a Bolsa”

Se (aP > aC) então

Se ( aP> aB) entao

msg<- “ O artigo mais solicitado foi a pulseira”

Senao

msg<- “O artigo mais solicitado foi a bolsa

senao

se ( aC> aB) entao

msg<- “ O artigo mais vendido foi o colar”

senao

msg <- “ O artigo mais vendido foi a bolsa”

vP cP, cC, cB, aP, aC, aB, at, ad, cont

You might also like