All homework for trem 5


Attention

ທີ່ສົ່ງໃຫ້ ເພາະຮັກ 😊 . ແຕ່ຂໍຮ້ອງ ຢ່າກັອບເອົາທຸກຢ່າງໄປວາງ ຢ່າງໜ້ອຍປ່ຽນຊື່ຕົວແປ ຄຳເວົ້າ ຫຼື ຂໍ້ຄວາມ ໃນ code ຫຼື ຫົວຂໍ້ແຕ່ລະອັນ ແລະ ລອງເອົາໄປ run ເບິ່ງ output ກ່ອນ. ລອງເອົາໄປເປັນຕົວຢ່າງ ແລະ ທຳຄວາມເຂົ້າໃຈແຕ່ລະໂປຣແກຣມ ຫຼື ບໍ່ເຂົ້າໃຈກໍຖາມຂ້ອຍໄດ້ ຂ້ອຍຍິນດີຊ່ວຍສະເໝີ. ຫວັງວ່າສິ່ງນີ້ຈະຊ່ວຍເຈົ້າໄດ້ ແລະ ກໍຫວັງວ່າເຈົ້າຈະເຂົ້າໃຈ 🙂

ປິ່ນແກ້ວ ເຂັມຄຳພູມີ


Exercise 1: ອ່ານຄ່າສຳປະສິດ x ແລະ y ເທິງແກນເຄົ້າຈາກນັ້ນຄຳນວນຫາຄ່າຂອງ r ແລະ theta ຂອງພິກັດດັ່ງກ່າວ


import math
x,y  = float(input ('x value = ')),float(input('y value = '))
r = math.sqrt(x**2 + y**2)

theta = math.atan(y/x) #atan is arctan(tan^-1)
print('round =',format(r,'.2f'))
print('theta = ',format(theta,'.2f'))

Exercise 2: create random password


import random
import string

char = string.ascii_letters
digit = string.digits
password = char+digit
password_length = 6

pwd = ''
for i in range(password_length):
  pwd +=''.join(random.choice(password))

print(pwd)

Exercise 3: ຄິດໄລ່ດອກເບ້ຍ

amount = int(input('amount ='))
rate = int(input('rate= '))
           
period = int(input('time = '))

income_rate = (rate/100)*amount
one_year = income_rate + amount

i = float(income_rate + amount)
income = i+((rate/100)*i)
  
if period == 1:
        total_one_year = i
        print(total_one_year)
else :
        income_total = float(income+((rate/100)*income))
        print(money

Exercise 4

create random number of second between 100,000 to 1,000,000 then convert them into minute, hour and second


import random
random_number = random.randint(100_000,1_000_001)
print('random number is', random_number)
h = random_number//3600
m = random_number%3600//60
random_number%=60
s = random_number
print (f'time is {h}:{m}:{s}')
print('second = ',format(s,'.2f'), '\nminute = ', format(m,'.2f'), '\nhour = ', format(h,'.2f'))

Exercise 5: ຄິດໄລ່ຄ່າຝາກລົດ


h_time_in = int(input('hour:'))
m_time_in = int(input('minute:'))
print('\nenter time you get out')
h_time_out = int(input('hour:'))
m_time_out = int(input('minute:'))

m_1 = ((h*60)+m_time_out) - m_time_in
#print (m_1)
h = m_1//60
m = m_1%60//1

if m>1:
  h_up = h+1
  print(f'total time is {h} hours and {m} minutes or {m_1} minutes, but i do not care what your time is, i am gonna take it as {h_up} hours\n')
else:
  print(f'total time is {h} hour and {m} minutes or {m_1} minutes\n')
if m_1 <15:
  print('park free for 15 minutes\n')
elif 15 <= m_1 <= 180 :
  h_up = h+1
  money = h_up*3000
  print('you have to pay ', m ,'kip\n' )
elif 181 <= m_1 <= 360:
  h_up = h+1
  money = (h_up * 6000)-9000
  print(f'you have to pay {m} kip\n')
elif m_1 > 360:
  money = 50_000
  print(f'you have to pay {m} kip\n')

Exercise 6

ໂປຣແກຣມຄິດໄລ່ ແລະຈຳກັດ ນຳ້ໜັກໃນລິບ

weight = 0
limit = 450
while weight < limit:
  for p in range(1,limit):
    person = int(input(f'person {p} :'))
    weight += person
    
    while weight > limit:
      print('weight = ', weight,'please get out')
      weight -= person
      person = int(input(f'person {p} :'))
      weight += person
    if 445 <= weight <= limit :
        print("this is enough, let's go!")
        break
    print('weight = ',weight)
  print('final weight: ',weight)
  break

Exercise : 7

ນັບຈຳນວນຕົວອັກສອນ ພິມໃຫຍ່ ພິມນ້ອຍ ຕົວເລກ ຜົນບວກທັງໝົດຂອງຕົວເລກໃນຂໍ້ຄວາມ ແລະ ຈັດຕົວເລກແຕ່ລະຕົວເຂົ້າໃນລິສ ແລ້ວລຽງລຳດັບຕົວເລກແຕ່ໜ້ອຍຫາຫຼາຍ

txt = input('type your message : ')
print('length of your message is : ',len(txt))
digit = lowercase = uppercase = 0
sum = 0
mx = 0
lst = []
for p in txt:
    if '0' <= p <= '9':
        digit += 1
        sum += int(p)
        if (int(p) > mx) and (int(p)%2==0):
            mx = int(p)
        lst.append(int(p))
    if 'A' <= p <= 'Z':
        uppercase += 1
    if 'a' <= p <= 'z':
        lowercase += 1
for pin in range(len(lst)):
    for keo in range(len(lst) - pin- 1):
      if lst[keo] > lst[keo+1]:
        lst[keo],lst[keo+1] = lst[keo+1],lst[keo]
print('digit in your message :', digit)
print('uppercase in your message : ', uppercase)
print(' lowercase in your message : ',lowercase)
print('summation of all number : ',sum)
print('Maximum even munber in your message :  ',mx)
print('all number in your message :',lst)

Exercise : 8 ຮັບອິນພຸດເລກຈຳນວນເຕັມ ກວດຫາຕົວເລກທີ່ມີຄ່າໃຫຍ່ສຸດ ແລະ ບວກຕົວເລກທັງໝົດ


a = input('enter number: ')
count_a = len(a)
print(count_a)
print(a[1])

mn = 9
mx = 0
sum = 0
for i in range(count_a):
  num = int(a[i])
  sum += num
  if mn > num:
    mn = num
  if mx < num:
    mx = num
    
print('total: ',sum)
print('min:',mn,'\nmax', mx)

Exercise 9

ຂຽນໂປຣແກຣມນັບຕົວອັກສອນພິມໃຫຍ່ ອິນພຸດຂໍ້ຄວາມທີ່ປະກອບດ້ວຍຕົວອັກສອນພິມນ້ອຍໃຫຍ່ ຕົວເລກ ສັນຍາລັກ ຍະວ່າງ ນັບຈຳນວນຕົວອັກສອນພິມໃຫຍ່ ແລະສະແດງຈຳນວນ ຕົວອັກສອນພິມໃຫຍ່


msg = input('enter your message : ')
cap = low = num = sym = spc = 0
len = len(msg)
for i in msg:
  if '0' <= i <= '9':
    num += 1
  if i.isupper():
    cap += 1
  if i.islower():
    low += 1
  if i.isspace():
    spc += 1
char_len = num + cap + low + spc
sym = len - char_len
print('numbers: ', num)
print('Uppercasse : ', cap)
print('Lowercase : ', low)
print('Spaces : ', spc)
print('Symbols: ',sym)

Exercise 10 ຄິດໄລ່ບໍລິມາດຮູບເລຂາຄະນິດ

import math
def menu():
    print("1.Sphere,2.Cube,3.Cylinder,0.Cancel\n")
    choice = int(input("Enter number of menu:\n"))
    return choice
def sphere():
    r_sphere = float(input(radius: "))
    v_sphere = (4 / 3) * math.pi * (r_sphere ** 2)
    print('V = ', v_sphere)
    return v_sphere
def cube():
    l = float(input("long: "))
    w = float(input("width: "))
    h = float(input("height: "))
    v_cube = l*w*h
    print('V = ', v_cube)
    return v_cube
def cylinder():
    r = float(input("radius: "))
    h = float(input("height: "))
    v_cyl = math.pi*(r**2)*h
    print('V = ', v_cyl)
    return v_cyl
select = menu()
if select == 1:
    print('sphere')
    vs = sphere()
if select == 2:
  print('cube')
  vc = cube()
if select == 3:
    print('cylinder') 
    vcy = cylinder() 
if select == 0:
    print("canceled")

Notes mentioning this note


ນີ້ຄືກຣາຟທີ່ລິ້ງໄປຫາທຸກໜ້າໃນ garden ນີ້ 🕸️.