0% found this document useful (0 votes)
6 views4 pages

Pyhton

The document contains various Python programming exercises demonstrating basic concepts such as variable types, input/output, string manipulation, control flow (if-else statements), and list operations. It includes examples of arithmetic operations, string formatting, and conditional checks. Additionally, there are exercises that involve defining functions and using loops to process lists.

Uploaded by

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

Pyhton

The document contains various Python programming exercises demonstrating basic concepts such as variable types, input/output, string manipulation, control flow (if-else statements), and list operations. It includes examples of arithmetic operations, string formatting, and conditional checks. Additionally, there are exercises that involve defining functions and using loops to process lists.

Uploaded by

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

excer 1

print("Welcome to Advanced Python Programming Professional.")

x = 1
if x == 1:
print("welcome")

print("welcome")

myint = 7
print(myint)

myfloat = 7.1
print(myfloat)
myfloat = float(7)
print(myfloat)

mystring = 'hello'
print(mystring)
mystring = "hello"
print(mystring)

mystring = "Don't worry about apostrophes"


print(mystring)

one = 1
two = 2
three = one + two
print(three)

hello = "hello"
world = "world"
helloworld = hello + " " + world
print(helloworld)

mystring = "hello"
print (mystring)
myfloat = float(10)
print(myfloat)
myint = int(20.1)
print(myint)

excer 2
num1 = float(input("enter the 1st number"))
print("hasil" + str(num1))

num2 = float ( input("data baru"))


print ("hasil" + str(num2))

add = float (num1 + num2)


print(str(add))

sub = float (num1 - num2)


print(str(sub))

jhon
name = "John"
age = 23
print("%s is %d years old." % (name, age))

mylist = [1,2,3]
print("A list: %s" % mylist)

excer 4
astring = "Hello world!"
print(astring[3:7])

astring = "Hello world!"


print(astring[-7:-3])

astring = "Hello world!"


print(astring[3:7:2])

astring = "Hello world!"


print(astring[3:7])
print(astring[3:7:1])

year = 2021
string = "it is going to be amazing in the year {}"
print (string.format (year))

s = "I Love Advanced Python Programming Professional"


print(len(s))

print(s.index("a"))

print(s.count("s"))
print(s[:5])
print(s[12])
print(s[1:2])
print(s[-5:])
print(s.split(" "))

astring = "Hello world!"


print(astring[::-1])

astring = "Hello world!"


print(astring.startswith("Hello"))
print(astring.endswith("asdfasdfasdf"))

qty = 15
item = 16
fees = 50.50
quotation = "the total fee for {} pieces of {} cost {}."

if,else
x = 2
print(x == 2) # prints out True
print(x == 3) # prints out False
print(x < 3) # prints out True

name = "John"
age = 23
if name == "John" and age == 23:
print("Your name is John, and you are also 23 years old.")
if name == "John" or name == "Rick":
print("Your name is either John or Rick.")

name = "John"
if name in ["John", "Rick"]:
print("Your name is either John or Rick.")

x = 2
if x == 2:
print("x equals two!")
else:
print("x does not equal to two.")

x = [1,2,3]
y = [1,2,3]
print(x == y) # Prints out True
print(x is y) # Prints out False

print(not False) # Prints out True


print((not False) == (False)) # Prints out False

excer 5
num1 = float(input("enter the 1st number"))
num2 = float ( input("data baru"))

choice = input("select option (+, -, *, /,):")

if choice == "+" :
answer = num1 + num2
elif choice == "-" :
answer = num1 - num2
elif choice == "*" :
answer = num1 * num2
elif choice == "/" :
answer = num1 / num2
else :
print("tidak ada hasil")

print(answer)

excer 6
numbers = [
951, 402, 984, 651, 360, 69, 408, 319, 601, 485, 980, 507, 725, 547, 544,
615, 83, 165, 141, 501, 263, 617, 865, 575, 219, 390, 984, 592, 236, 105, 942, 941,
386, 462, 47, 418, 907, 344, 236, 375, 823, 566, 597, 978, 328, 615, 953, 345,
399, 162, 758, 219, 918, 237, 412, 566, 826, 248, 866, 950, 626, 949, 687, 217,
]
for x in numbers:
if x == 237:
continue
#check if x is even
elif x % 2 == 0:
print (x)
else:
continue
for x in numbers:
if x == 360:
continue
#check if x is even
elif x % 4 == 2:
print (x)
else:
continue

mylist = []
mylist.append(1)
mylist.append(2)
mylist.append(3)
print (mylist[0]) # prints 1
print (mylist[1]) # prints 2
print (mylist[2]) # prints 3
# prints out 1,2,3
for x in mylist:
print(x)

excer 7
homework

excer 8
homework
example
def computation (num1,num2,choice):
if choice == " + ":
answer = a + b

return answer

x = sum_two_numbers(1,2)
print(x)

You might also like