import random print("Ask the Magic Python Ball a question:") question = input()…
- User
import random
print("Ask the Magic Python Ball a question:") question = input() print("") print("Loading...") num = random.randint(1,8) if num == 1: print("") print("Magic Python Ball: Ask again later, I'm not gonna answer your stupid question.") elif num == 2: print("") print("Magic Python Ball: I'm not going to answer just to be petty. ") elif num == 3: print("") print("Magic Python Ball: Totally not, bro.") elif num == 4: print("") print("Magic Python Ball: Nah") elif num == 5: print("") print("Magic Python Ball: IDK") elif num == 6: print("") print("Magic Python Ball: Yuh") elif num == 7: print("") print("Magic Python Ball: Nuh uh") elif num == 8: print("") print("Magic Python Ball: I uhhhh-") This won't work in the terminal and it just crashes when I input an answer.
- Assistant
I noticed there is an error in the code. The "print" statement after the elif block for num == 8 is not properly formatted. It seems like there is an unfinished statement.
To fix this issue, you can remove the incomplete statement or replace it with a valid print statement. For example, you can use:
elif num == 8: print("") print("Magic Python Ball: I'm not sure, try again later.")This should resolve the error and allow the program to run without crashing.
- User
Can you convert it to C or whatever program is used for making exes? I think it would run better in that format.
- Assistant
Certainly! Here's the same code in C language:
#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { printf("Ask the Magic Python Ball a question:\n"); char question[100]; fgets(question, sizeof(question), stdin); printf("\nLoading...\n"); srand(time(NULL)); int num = rand() % 8 + 1; if (num == 1) { printf("\nMagic Python Ball: Ask again later, I'm not gonna answer your stupid question.\n"); } else if (num == 2) { printf("\nMagic Python Ball: I'm not going to answer just to be petty.\n"); } else if (num == 3) { printf("\nMagic Python Ball: Totally not, bro.\n"); } else if (num == 4) { printf("\nMagic Python Ball: Nah\n"); } else if (num == 5) { printf("\nMagic Python Ball: IDK\n"); } else if (num == 6) { printf("\nMagic Python Ball: Yuh\n"); } else if (num == 7) { printf("\nMagic Python Ball: Nuh uh\n"); } else if (num == 8) { printf("\nMagic Python Ball: I uhhhh- I'm not sure, try again later.\n"); } return 0; }