First
This commit is contained in:
22
Acara-7/input-output.py
Executable file
22
Acara-7/input-output.py
Executable file
@@ -0,0 +1,22 @@
|
||||
# Simple Input and Output in Python
|
||||
|
||||
# Ask the user to enter their name
|
||||
name = input("Enter your name: ") # input() gets user input as a string
|
||||
|
||||
# Print a greeting message using the input
|
||||
print("Hello,", name) # print() outputs text to the screen
|
||||
|
||||
# Ask the user to enter their age
|
||||
age = input("Enter your age: ")
|
||||
|
||||
# Print a message with the user's age
|
||||
print("You are", age, "years old.")
|
||||
|
||||
|
||||
var = int(input("Enter an Number: ")) # Convert input to integer
|
||||
print("You entered the Number:", var)
|
||||
flt = float(input("Enter a floating-point number: ")) # Convert input to float
|
||||
print("You entered the float:", flt)
|
||||
# Demonstrating formatted output
|
||||
print("Formatted output: Name: {}, Age: {}, Integer: {}, Float: {:.2f}".format(name, age, var, flt))
|
||||
print(f"Formatted output using f-string: Name: {name}, Age: {age}, Integer: {var}, Float: {flt:.2f}")
|
||||
5
Acara-7/input-output2.py
Executable file
5
Acara-7/input-output2.py
Executable file
@@ -0,0 +1,5 @@
|
||||
nama = input("Masukkan nama Anda: ")
|
||||
umur = int(input("Masukkan umur Anda: "))
|
||||
tinggi = float(input("Masukkan tinggi badan Anda (dalam cm): "))
|
||||
|
||||
print ("Halo %s, Umur kamu %i tahun dan tinggi badambu %f cm." % (nama, umur, tinggi))
|
||||
3
Acara-7/input-output3.py
Executable file
3
Acara-7/input-output3.py
Executable file
@@ -0,0 +1,3 @@
|
||||
print (1, 3, 5, 7)
|
||||
print (1,2,3,4, sep='*')
|
||||
print (1,2,3,4, sep='#', end='&')
|
||||
Reference in New Issue
Block a user