#string= a series of text, can include numbers.
first_name= "Bro"
food = "Pi"
email = "alsc@[Link]"
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 ([Link])
#print (math.e)
#result = [Link](x)
#x = 25
#print (result)
# ceil = always rounds up
# floor = always rounds down
x = 9.1
result = [Link] (x)
print (result)
y = 9.9
result = [Link] (y)
print (result)
import math
radius = float(input ("Enter the radius o a circle:"))
circumference = 2 * [Link] * radius
print (f"The circumference is: { circumference}")
import math
adjacent = float (input("Enter the adjacent:"))
opposite = float (input ("Enter the opposite:"))
hypotenuses = [Link] ( (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 [Link];
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 ([Link]);
[Link]("You are playing a game! Press q or Q to quit");
String response = [Link]();
if ([Link]("q") || [Link]("Q")) {
[Link]("You quit the game");
}
else {
[Link]("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) {
[Link]("It is hot outside");
}
else if (temp>= 20 && temp<=30) {
[Link]("It is warm outside");
}
else {
[Link]("It is cold outside");
}
}
}
While loop
package aulas;
import [Link];
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([Link]);
String name = "";
while([Link]()) {
[Link]("Enter your name: ");
name = [Link]();
}
[Link]("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--) {
[Link](i);
}
[Link]("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