mercredi 30 juin 2021

Python: if-else statement, printing 'Weird' if a given integer is odd or it's even but within a particular range shown below, and 'Not Weird' if not

I'm trying to create an if-else function which will print 'Weird' if an integer n is odd, 'Not Weird' if it's even and between 2 and 5 inclusive, 'Weird' if it's lies between 6 and 20 and not weird if it's an even integer more than 20. I tried the following code but it wouldn't run, can you tell me what the issue is?

#!/bin/python

import math
import os
import random
import re
import sys

if __name__ == '__main__':
    n = int(input().strip())

if n % 2 = 1:
    print ("Weird")

else:
    if n range(2,5):
        print:("Not Weird")

    else:
        if n range(6,20):
            print("Weird")

        else:
            print("Not Weird")

Aucun commentaire:

Enregistrer un commentaire