vietanngotuong
New member
#informatics #Test #11 #Python #Coding ## Kiểm tra tin học 11 Python
## Vấn đề 1
Viết một chương trình Python để in 100 số Fibonacci đầu tiên.
`` `Python
def fibonacci :
Nếu n <2:
trả lại n
Trả về Fibonacci (N - 1) + Fibonacci (N - 2)
Đối với tôi trong phạm vi (1, 101):
in (fibonacci (i))
`` `
## Bài toán 2
Viết một chương trình Python để kiểm tra xem một số là số nguyên tố.
`` `Python
def is_prime :
Nếu n <2:
trả lại sai
Đối với i trong phạm vi (2, int (n ** 0,5) + 1):
Nếu n % i == 0:
trả lại sai
trả về đúng
n = int (input ("nhập một số:"))
if is_prime :
print ("{} là Prime" .format )
khác:
print ("{} không phải là Prime" .format )
`` `
## Bài toán 3
Viết một chương trình Python để tìm GCD của hai số.
`` `Python
def gcd (a, b):
Trong khi B! = 0:
a, b = b, a % b
trả lại a
a = int (input ("Nhập số đầu tiên:"))
b = int (input ("Nhập số thứ hai:"))
PRIN
`` `
## Vấn đề 4
Viết một chương trình Python để tìm LCM của hai số.
`` `Python
def lcm (a, b):
Return (A * B) // GCD (A, B)
a = int (input ("Nhập số đầu tiên:"))
b = int (input ("Nhập số thứ hai:"))
PRINT ("LCM của {} và {} là {}".
`` `
## Bài toán 5
Viết một chương trình Python để chuyển đổi số thập phân thành nhị phân.
`` `Python
def decimal_to_binary :
nhị phân = ""
Trong khi n> 0:
nhị phân += str (n % 2)
n // = 2
Trả lại nhị phân [::-1]
n = int (input ("Nhập số thập phân:"))
PRIN
`` `
## hashtags
* #Python
* #Mã hóa
* #Algorithms
* #toán học
* #Giải quyết vấn đề
=======================================
#informatics #Test #11 #Python #Coding ##Informatics Test 11 Python
##Problem 1
Write a Python program to print the first 100 Fibonacci numbers.
```python
def fibonacci:
if n < 2:
return n
return fibonacci(n - 1) + fibonacci(n - 2)
for i in range(1, 101):
print(fibonacci(i))
```
##Problem 2
Write a Python program to check if a number is prime.
```python
def is_prime:
if n < 2:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
n = int(input("Enter a number: "))
if is_prime:
print("{} is prime".format)
else:
print("{} is not prime".format)
```
##Problem 3
Write a Python program to find the GCD of two numbers.
```python
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
print("The GCD of {} and {} is {}".format(a, b, gcd(a, b)))
```
##Problem 4
Write a Python program to find the LCM of two numbers.
```python
def lcm(a, b):
return (a * b) // gcd(a, b)
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
print("The LCM of {} and {} is {}".format(a, b, lcm(a, b)))
```
##Problem 5
Write a Python program to convert a decimal number to binary.
```python
def decimal_to_binary:
binary = ""
while n > 0:
binary += str(n % 2)
n //= 2
return binary[::-1]
n = int(input("Enter a decimal number: "))
print("The binary representation of {} is {}".format(n, decimal_to_binary))
```
##Hashtags
* #Python
* #Coding
* #Algorithms
* #Math
* #problem-solving
## Vấn đề 1
Viết một chương trình Python để in 100 số Fibonacci đầu tiên.
`` `Python
def fibonacci :
Nếu n <2:
trả lại n
Trả về Fibonacci (N - 1) + Fibonacci (N - 2)
Đối với tôi trong phạm vi (1, 101):
in (fibonacci (i))
`` `
## Bài toán 2
Viết một chương trình Python để kiểm tra xem một số là số nguyên tố.
`` `Python
def is_prime :
Nếu n <2:
trả lại sai
Đối với i trong phạm vi (2, int (n ** 0,5) + 1):
Nếu n % i == 0:
trả lại sai
trả về đúng
n = int (input ("nhập một số:"))
if is_prime :
print ("{} là Prime" .format )
khác:
print ("{} không phải là Prime" .format )
`` `
## Bài toán 3
Viết một chương trình Python để tìm GCD của hai số.
`` `Python
def gcd (a, b):
Trong khi B! = 0:
a, b = b, a % b
trả lại a
a = int (input ("Nhập số đầu tiên:"))
b = int (input ("Nhập số thứ hai:"))
PRIN
`` `
## Vấn đề 4
Viết một chương trình Python để tìm LCM của hai số.
`` `Python
def lcm (a, b):
Return (A * B) // GCD (A, B)
a = int (input ("Nhập số đầu tiên:"))
b = int (input ("Nhập số thứ hai:"))
PRINT ("LCM của {} và {} là {}".
`` `
## Bài toán 5
Viết một chương trình Python để chuyển đổi số thập phân thành nhị phân.
`` `Python
def decimal_to_binary :
nhị phân = ""
Trong khi n> 0:
nhị phân += str (n % 2)
n // = 2
Trả lại nhị phân [::-1]
n = int (input ("Nhập số thập phân:"))
PRIN
`` `
## hashtags
* #Python
* #Mã hóa
* #Algorithms
* #toán học
* #Giải quyết vấn đề
=======================================
#informatics #Test #11 #Python #Coding ##Informatics Test 11 Python
##Problem 1
Write a Python program to print the first 100 Fibonacci numbers.
```python
def fibonacci:
if n < 2:
return n
return fibonacci(n - 1) + fibonacci(n - 2)
for i in range(1, 101):
print(fibonacci(i))
```
##Problem 2
Write a Python program to check if a number is prime.
```python
def is_prime:
if n < 2:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
n = int(input("Enter a number: "))
if is_prime:
print("{} is prime".format)
else:
print("{} is not prime".format)
```
##Problem 3
Write a Python program to find the GCD of two numbers.
```python
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
print("The GCD of {} and {} is {}".format(a, b, gcd(a, b)))
```
##Problem 4
Write a Python program to find the LCM of two numbers.
```python
def lcm(a, b):
return (a * b) // gcd(a, b)
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
print("The LCM of {} and {} is {}".format(a, b, lcm(a, b)))
```
##Problem 5
Write a Python program to convert a decimal number to binary.
```python
def decimal_to_binary:
binary = ""
while n > 0:
binary += str(n % 2)
n //= 2
return binary[::-1]
n = int(input("Enter a decimal number: "))
print("The binary representation of {} is {}".format(n, decimal_to_binary))
```
##Hashtags
* #Python
* #Coding
* #Algorithms
* #Math
* #problem-solving