输入询问循环

时间:2018-10-12 20:41:34

标签: python loops

这是到目前为止我的代码的样子;

while True:
    ques = input("What product? ")
    print(ques)
    if ques == sausage:
        print("That's right!")
        break
    else:
        print("That's not what I'm thinking of")
        while False:
            return

我想做的几乎是,如果输入的是香肠,程序将打印谢谢并停在那里。如果还有其他问题,应该打印错误并再次询问。

1 个答案:

答案 0 :(得分:0)

只需将 public class heaps { public void maxHeap(int arr[], int index, int n) { int largest = index; n = arr.length; int l = (2*index) + 1; int r =(2*index) + 2; int size = arr.length; if ((l < n) && (arr[l] > arr[largest])) { largest = l; } else { largest = index; } if ((r < size) && arr[r] > (arr[largest])) { largest = r; } if (largest != index) { int temp = arr[index]; arr[index] = arr[largest]; arr[largest] = temp; maxHeap(arr, largest, n); } } public void buildMaxHeap(int arr[]) { int n = arr.length; for (int index = (n / 2) - 1; index >= 0; index--) { maxHeap(arr, index, n); } } public void sort(int arr[]) { int n = arr.length; buildMaxHeap(arr); for (int index = n - 1; index >= 0; index--) { int temp = arr[0]; arr[0] = arr[index]; arr[index] = temp; n = n - 1; maxHeap(arr, index, 0); } } public void printArray(int arr[]) { int n = arr.length; for (int i=0; i<n; ++i) System.out.print(arr[i]+" "); System.out.println(); } public static void main(String[] args) { heaps o = new heaps(); int array[] = {15, 9, 11, 5, 6, 7}; heaps.sort(array); heaps.printArray(array); heaps.maxHeap(array, 0, array.length); heaps.printArray(array); } } 放在引号中-sausage