Advertisement
Guest User

test

a guest
Jun 15th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.46 KB | None | 0 0
  1. def wtf():
  2.     print("Would you like to try this program?")
  3.     print("You have to answer with yes or no and press enter")
  4.     print("Just advice if you say no I will send you in a LOOP>>>>")
  5.     command = input()
  6.     if command == "yes":
  7.         start_menu()
  8.     else:
  9.         no()
  10.  
  11.  
  12. def start_menu():
  13.     print("In this program You can try all 7 of the tasks from LISTS(file 3):")
  14.     print("To continue Just type down the task number (1, 2,3 .... 7) and press Enter.")
  15.     print()
  16.     print()
  17.     command = input()
  18.     if command == "1":
  19.         task1()
  20.     elif command == "2":
  21.         task2()
  22.     elif command == "3":
  23.         task3()
  24.     elif command == "4":
  25.         task4()
  26.     elif command == "5":
  27.         task5()
  28.     elif command == "6":
  29.         task6()
  30.     elif command == "7":
  31.         task7()
  32.  
  33.  
  34. def task1():
  35.     print("You have selected Task 01. Array Contains Element")
  36.     print("Write down a list of integers on the first line of the console like:(1 2 3 4 5 6 7) and then press Enter")
  37.     print("After that write down a number You wish to check if its in the list you added first and press Enter again")
  38.     print("And I will give you and answer, by confirming with yes or no.")
  39.     nums = [int(item) for item in input().split(" ")]
  40.     num = int(input())
  41.     print("Result:")
  42.     if num in nums:
  43.         print("yes")
  44.     else:
  45.         print("no")
  46.     print()
  47.     print()
  48.     start_menu()
  49.  
  50.  
  51. def task2():
  52.     print("You have selected Task 02. Smallest Element in Array")
  53.     print("Here you will give me a whole list of integers and I will tell you which is the smallest one.")
  54.     print("Write down a list of integers like (1 2 3 4 5 6 7 8 9) And press ENTER")
  55.     print()
  56.     print()
  57.     nums = [int(item) for item in input().split(" ")]
  58.     print("Result:")
  59.     print(min(nums))
  60.     print()
  61.     print()
  62.     start_menu()
  63.  
  64.  
  65. def task3():
  66.     print("You have selected Task 03. Reverse Array In-place")
  67.     print("You can give me a whole list of integers and I will reverse it for you.")
  68.     print("So just type down your list. Like (1 2 3 4 5 6 7 8) and press Enter")
  69.     nums = [int(item) for item in input().split(" ")]
  70.  
  71.     nums.reverse()
  72.     print("Result:")
  73.     for num in nums:
  74.         print(num, end=" ")
  75.     print()
  76.     print()
  77.     start_menu()
  78.  
  79.  
  80. def task4():
  81.     print("You have selected Task 04. Sort Array Using Bubble Sort")
  82.     print("You can give me a whole list of integers and I will sort it for you. Using the Bubble Sort Method")
  83.     print("Just type down your list like (1 2 3 4 5 6 7 8) and press Enter")
  84.  
  85.     def short_bubble_sort(a_list):
  86.         exchanges = True
  87.         pass_num = len(a_list) - 1
  88.         while pass_num > 0 and exchanges:
  89.             exchanges = False
  90.             for i in range(pass_num):
  91.                 if a_list[i] > a_list[i + 1]:
  92.                     exchanges = True
  93.                     temp = a_list[i]
  94.                     a_list[i] = a_list[i + 1]
  95.                     a_list[i + 1] = temp
  96.             pass_num = pass_num - 1
  97.  
  98.     nums = [int(item) for item in input().split(" ")]
  99.     short_bubble_sort(nums)
  100.     print("Result:")
  101.     for num in nums:
  102.         print(num, end=" ")
  103.     print()
  104.     print()
  105.     start_menu()
  106.  
  107.  
  108. def task5():
  109.     print("You have selected Task 05. Sort Array Using Insertion Sort")
  110.     print("You can give me a whole list of integers and I will sort it for you. Using the Insertion Sort Method")
  111.     print("Just type down your list like (1 2 3 4 5 6 7 8) and press Enter")
  112.  
  113.     def insertion_sort(arr):
  114.         for i in range(1, len(arr)):
  115.             key = arr[i]
  116.             j = i - 1
  117.             while j >= 0 and key < arr[j]:
  118.                 arr[j + 1] = arr[j]
  119.                 j -= 1
  120.             arr[j + 1] = key
  121.  
  122.     nums = [int(item) for item in input().split(" ")]
  123.     insertion_sort(nums)
  124.     print("Result:")
  125.     for num in nums:
  126.         print(num, end=" ")
  127.  
  128.  
  129. def task6():
  130.     print("You have selected Task 6. Insertion Sort Using List")
  131.     print("You can give me a whole list of integers and I will sort it for you. Using the Insertion Sort Method")
  132.     print("Just type down your list like (1 2 3 4 5 6 7 8) and press Enter")
  133.  
  134.     def insertion_sort(arr):
  135.         for i in range(1, len(arr)):
  136.             key = arr[i]
  137.             j = i - 1
  138.             while j >= 0 and key < arr[j]:
  139.                 arr[j + 1] = arr[j]
  140.                 j -= 1
  141.             arr[j + 1] = key
  142.  
  143.     nums = [int(item) for item in input().split(" ")]
  144.     insertion_sort(nums)
  145.     print(f"Result:")
  146.     for num in nums:
  147.         print(num, end=" ")
  148.     print()
  149.     print()
  150.     start_menu()
  151.  
  152.  
  153. def no():
  154.     while True:
  155.         print("You HAD to say YES.")
  156.  
  157.  
  158. def task7():
  159.     print("You have selected Task 07. Largest N Elements")
  160.     print("Here you will give me a whole list of integers. And a specific X number. I will sort the list for you")
  161.     print("in reverse order and i will show you the X number of items you have asked for.")
  162.     print("So first type down your list like (1 2 3 4 5 6 7 8) and press Enter")
  163.     nums = [int(item) for item in input().split(" ")]
  164.     print(f"Now type down your X number:")
  165.     count = int(input())
  166.  
  167.     nums.sort(reverse=True)
  168.  
  169.     start = 0
  170.     sorted_nums = []
  171.  
  172.     while count != 0:
  173.         sorted_nums += [nums[start]]
  174.         start += 1
  175.         count -= 1
  176.     print("Result:")
  177.     for num in sorted_nums:
  178.         print(num, end=" ")
  179.     print()
  180.     print()
  181.     start_menu()
  182.  
  183.  
  184. wtf()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement