Exemplo n.º 1
0
def main():
    sys.path.insert(
        1, r"/home/rahulrajan/Documents/dev/scripts/"
        r"cdacAssignments/Assignment9")
    from question2 import input_positive_integer
    num = input_positive_integer("Enter the limiting number : ")
    print("Sum until ", num, ":", sum(num))
Exemplo n.º 2
0
def main():
    sys.path.insert(1, r"/home/rahulrajan/Documents/dev/scripts/"
                    r"cdacAssignments/Assignment9")
    from question2 import input_positive_integer
    month_days = input_positive_integer("Please enter the number days in the"
                                        " month : ")
    day = input("Which days the the first day of the month ?\n"
                "Please select from [Sun, Mon, Tue, Wed, Thu, Fri, Sat] : ")\
                .upper()
    plot_calendar(month_days, day)
    print("-"*50)
Exemplo n.º 3
0
def main():
    path.insert(
        1, r"/home/rahulrajan/Documents/dev/scripts/"
        r"cdacAssignments/Assignment9")
    from question2 import input_positive_integer
    print("Select any one of the option: "
          "\n1. Run People Color"
          "\n2. Run Swedish Thief Translator")
    opt = input_positive_integer("Please Select from 1 or 2 : ")
    if opt == 1:
        people_colour()
    elif opt == 2:
        string = input("Please enter some string : ")
        print("Encoded text : ", srl_translator(string))
    else:
        print("Err! Invalid option selected")
Exemplo n.º 4
0
'''Q7: Write a Python program to find the sum of natural numbers up to n
 using recursive function'''
from question2 import input_positive_integer


def sum_of_series(lim, a=1):
    if (lim - 1 > 0):
        return a + sum_of_series(lim - 1, a + 1)
    else:
        return a


if __name__ == '__main__':
    num = input_positive_integer("Please input the limiting factor: ")
    print("-" * 50)
    print("Sum of all natural numbers till"
          " '{0}' is '{1}'".format(num, sum_of_series(num)))
    print("-" * 50)

# maximum recursion limit at number 998
Exemplo n.º 5
0
'''Q8: Write a Python program to convert decimal number into binary number
 using recursive function.'''
from question2 import input_positive_integer


def decimal_to_binary(num):
    if num == 0:
        return 0
    else:
        return num % 2 + (decimal_to_binary(num // 2) * 10)


if __name__ == '__main__':
    num = input_positive_integer("Please input a integer: ")
    print("-" * 50)
    print("Binary equivalent of"
          " '{0}' is '{1}'".format(num, decimal_to_binary(num)))
    print("-" * 50)
Exemplo n.º 6
0
# Q3: Write a Python program to find the H.C.F of two input number
from question2 import input_positive_integer


def euclidean_algo_hcf(a, b):
    if a < b:
        a, b = b, a
    rem = a % b
    if rem != 0:
        return euclidean_algo_hcf(b, rem)
    else:
        return b


if __name__ == "__main__":
    num1 = input_positive_integer("Input number 1 : ")
    num2 = input_positive_integer("Input number 2 : ")
    print("HCF of {0} and {1} : {2}".format(num1, num2,
                                            euclidean_algo_hcf(num1, num2)))
Exemplo n.º 7
0
""" Q4: Write a Python Program to find the factors of a number """

import time
from question2 import input_positive_integer


def factors(num):
    """ Accepts a string and return a list of factors of the number. """
    i = 1
    lst = []
    head = i
    tail = num
    while i <= num:
        head = i
        if tail <= head:
            break
        if num % i == 0:
            tail = num / i
            lst.append(i)
            lst.append(tail)
        i += 1
    return lst


if __name__ == "__main__":
    number = input_positive_integer("Enter any positive integer : ")
    start_time = time.time()
    print("Factors of '{0}' are {1}".format(number, factors(number)))
    print("Time Taken is '%s' Seconds" % (time.time() - start_time))