4: Repetition

4-1: Flowchart

** ถ้าใช้งานบนมือถือหรือ tablet แนะนำให้ใช้ Chrome หรือ Safari เท่านั้น **

แบบฝึกหัด 4-1 ข้อที่ 1

เขียนโปรแกรมตามผังงานข้าง ๆ นี้

n = 100 c = 0 while n > 0: n //= 2 c += 1 print(c) Ex().check_while(missing_msg="ใช้วงวนตามผังงาน") for v in [1, 2, 4, 8, 1024, 10394, 2983928]: Ex().has_equal_output(pre_code="n=" + str(v), incorrect_msg = "ผิด เช่น กรณี n = " +str(v)+ "'")
แบบฝึกหัด 4-1 ข้อที่ 2

เขียนโปรแกรมตามผังงานข้าง ๆ นี้

b = "100101011" n = len(b) k = 0 d = 0 while k < n: d += 2**k*int(b[n-k-1]) k += 1 print(d) Ex().check_while(missing_msg="ใช้วงวนตามผังงาน") for v in ["00", "00101", "1000000", "101010101", "11111111"]: Ex().has_equal_output(pre_code="b='"+v+"'", incorrect_msg = "ผิด เช่น กรณี b = '" +v+ "'")
แบบฝึกหัด 4-1 ข้อที่ 3

เขียนโปรแกรมตามผังงานข้าง ๆ นี้

n = 2 c = 0 while n>0: n = n-1 if n%3 == 0: n = n-c c += 1 print(c) Ex().check_while(missing_msg="ใช้วงวนตามผังงาน") for v in [20, 30, 50, 100, 349]: Ex().has_equal_output(pre_code="n="+str(v), incorrect_msg = "ผิด เช่น กรณี n = " + str(v))