-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgramming_Assignment_3.py
More file actions
59 lines (50 loc) · 1.37 KB
/
Programming_Assignment_3.py
File metadata and controls
59 lines (50 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
1. Python Program to Check if a Number is Positive, Negative or Zero:
```python
num = float(input("Enter a number: "))
if num > 0:
print("The number is positive")
elif num < 0:
print("The number is negative")
else:
print("The number is zero")
```
2. Python Program to Check if a Number is Odd or Even:
```python
num = int(input("Enter a number: "))
if num % 2 == 0:
print("The number is even")
else:
print("The number is odd")
```
3. Python Program to Check Leap Year:
```python
year = int(input("Enter a year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print(f"{year} is a leap year")
else:
print(f"{year} is not a leap year")
```
4. Python Program to Check Prime Number:
```python
num = int(input("Enter a number: "))
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if (num % i) == 0:
print(f"{num} is not a prime number")
break
else:
print(f"{num} is a prime number")
else:
print(f"{num} is not a prime number")
```
5. Python Program to Print all Prime Numbers in an Interval of 1-10000:
```python
print("Prime numbers between 1 and 10000:")
for num in range(1, 10001):
if num > 1:
for i in range(2, int(num ** 0.5) + 1):
if (num % i) == 0:
break
else:
print(num)
```