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

Algorithma

The document outlines a programming assignment for a student named Nayla Safa Zefiana Hafdini, requiring the completion of multiple tasks using Python in Visual Studio Code. Each task involves writing a specific program, including input and output requirements, and correcting errors in provided code snippets. The document includes detailed instructions and examples for each task, focusing on basic programming concepts such as data types, variables, and operators.
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)
9 views10 pages

Algorithma

The document outlines a programming assignment for a student named Nayla Safa Zefiana Hafdini, requiring the completion of multiple tasks using Python in Visual Studio Code. Each task involves writing a specific program, including input and output requirements, and correcting errors in provided code snippets. The document includes detailed instructions and examples for each task, focusing on basic programming concepts such as data types, variables, and operators.
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

Name : Nayla Safa Zefiana Hafdini

Student ID : 2312076
Class :B

Study Case - Tasks 4th Meeting

Instructions : Based on what we have discussed on previous meeting about datatype, variable
and operator, please do this programming exercise using Visual Studio Code Python. Write
down your program and the rest of it using English. Submit the assignment with the
description, the code and the running output capture.

Task 1 - Write a program that inputs four integer values and prints the multiplication of them.
#Task 1
#Inputs four integer values and prints the multiplication of them.

a = int(input("enter the first number: "))


b = int(input("enter the first number: "))
c = int(input("enter the first number: "))
d = int(input("enter the first number: "))
result = a*b*c*d
print("The product of the four numbers is:", result)

Output Task 1:
Task 2 - Write a program that calculates and prints the area and the perimeter of a square
when the size of one side is given.

Answer:
# Task 2
# Input the size of one side of the square
side = float(input("Enter the length of one side of the square: "))

# Calculate Area
area = side**2

# Calculate Perimeter
perimeter = side*4

# Print the result


print ("Area of the square is: ", area)
print ("Perimeter of square is: ",perimeter)

Output Task 2:

Task 3 - Write a program that, using a Python string, prints your name in the format shown
below after being prompted to input your first and the last name. Note that the last name
should come before the first name as shown.
Your full name is: last, first

Answer:
# Task 3

first_name = input("enter your first name: ")


last_name = input("enter your last name: ")
print("your full name is:", last_name + ", " + first_name)

Output Task 3:
Task 4 - Write a program that prompts the user to enter two integers. It then prints their sum.
Run your program three (3) times, each with different values for variables.
Answer:
# Task 4
# Write a program that prompts the user to enter two integers.
# It then prints their sum. Run your program three (3) times, each with
different values for variables.

num1 = int(input("Enter your first number: "))


num2 = int(input("Enter your second number: "))

result = num1 + num2

print("\nThe sum of those two values is:", result)

Output Task 4:

Task 5 – Locate the error or best replacement for this program below, show the output :
a) Program 1

x = int(input)("Enter a number: ")


y=4

result = x > y
print=(x, ">", y, "=", result)

result = x == y
print=(x, "==", y, "=", result)

result = x + x >=y
print(x, "==", y, "=", result)

Output Program 1:

Corrected Program 1:
x = int(input("Enter a number: ")) # the closing bracket on the word
“input” is moved to the end of the sentence
y = 4
result = x > y
print(x, ">", y, "=", result) # the equal sign after "print" is
ommited
result =x == y
print(x, "==", y, "=", result) # the equal sign after "print" is
ommited
result = x + x >=y
print(x, ">=", y, "=", result) # fixed the output massage
Output Corrected Program 1:

b) Program 2

print("Lets calculate the area of a circle!")

print("The formula to calculate the area is \nA = pi x r^2")

r = int(input("Enter the radius of a circle:


")) pi = 3.14
area = r x pi ^2

print("The area of a circle is:", area)

Output Program 2:

Corrected Program 2:
print("Lets calculate the area of a circle!")
print("The formula to calculate the area is \nA = pi x r^2")
r = int(input("Enter the radius of a circle: "))
pi = 3.14
area = r * pi * (r ** 2) #the "x" sign replaced with "*", and the
sign "**" is use to calculate r2
print("The area of a circle is:", area)
Output Corrected Program 2:

c) Program 3

printf("Welcome to the class!")

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

nim = int(input("Enter your student ID (2346xxx):


")) major = int(input("Enter your major: "))

printf("")

printf("Hello, Welcome",
Name) printf("Your student ID
is", NIM)
printf("You are a student majoring in", Major)

Output Program 3:
Corrected Program 3:
print("Welcome to the class!") # Printf() should be fixed to
print()
name = input("Enter your name: ")
nim = input("Enter your student ID (2346xxx): ")
major = (input("Enter your major: "))
print("") # Printf() should be fixed to print()
print("Hello, Welcome", name) # Printf() should be fixed to print()
print("Your student ID is", nim) # Printf() should be fixed to
print()
print("You are a student majoring in", major) # Printf() should be
fixed to print()

Output Corrected Program 3:

d) Program 4

decnum = int(input("Enter a decimal number (e.g. 17.7): "))"""Enter a decimal


number (e.g. 17.7): """
negnum = int(input("Enter a negative number (e.g. -17): "))"""Enter a negative
number (e.g. -17): ""

result = (decnum + negnum) / 2


print("The average obtained is: ". result)

Output Program 4:
Corrected Program 4:
decnum = float(input("Enter a decimal number (e.g. 17.7): ")) #
float use to handle decimal number
negnum = int(input("Enter a negative number (e.g. -17): ")) # int
use to negative number

result = (decnum + negnum) / 2


print("The average obtained is: ", result) # the sign used before
the word "result" is changed from "." to ","

Output Corrected Program 4:

e) Program 5
print("enter the first
number:")
number1=(input())
prnt("enter the second
number:") number2=(input()
print("enter the third
number:")
number2=(input())

result=number1+number2+number3
print("addition of the three
integer:"result)

Output Program 5:
Corrected Program 5:
print("enter the first number:")
number1=int(input()) # add "int" before (input())
print("enter the second number:") # changed prnt() to print()
number2=int(input()) # add the parentheses at the end
print("enter the third number:")
number2=int(input()) # changed number 2 to number 3 to correct the
"third number"

result=number1+number2+number3
print("addition of the three integer:",result) # the sign used
before the word "result" is changed from "." to ","

Output Corrected Program 5:

f) Program 6

print("enter the first


number:")
number1=int(input)
number2=int(input"enter the second
integer:") number3=int(("enter the third
integer:")) print("enter the fourth number:")
number4=(input()

result=number1*number3*number3*number3
print("the multiplication of the four
integer:",resu1t)
Output Program 6:

Corrected Program 6:
print("Enter the first number: ")
number1 = int(input()) # add parentheses

print("Enter the second integer") # add the "print("enter the


second integer")"
number2 = int(input()) # changed to "int(input)"

print("Enter the third integer") # add the "print("enter the third


integer")
number3 = int(input()) # changed to "int(input)"

print("Enter the fourth number")


number4= int(input()) #add the parentheses at the end

result = number1 * number2 * number3 * number4 # changed to


"number2 number3 number4"

print("The multiplication of the four integers: ", result) #


correct the "resu1t" to "result"

Output Corrected Program 6:

You might also like