Advertisement
Guest User

test

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