Pyhton
Pyhton
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)
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))
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])
year = 2021
string = "it is going to be amazing in the year {}"
print (string.format (year))
print(s.index("a"))
print(s.count("s"))
print(s[:5])
print(s[12])
print(s[1:2])
print(s[-5:])
print(s.split(" "))
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
excer 5
num1 = float(input("enter the 1st number"))
num2 = float ( input("data baru"))
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)