Prompt Title: (0)

Created 1 year ago
Votes 0
Views 351 times
0

Prompt Detail:

You can convert the provided C code to Python as follows:

python
import sys clothes = [] clothes_count = 0 money = 10 inprogress_clothe = None upgrade_quality = 0 upgrade_timer = 0 def print_flag(): try: with open("flag.txt", "r") as file: flag = file.readline().strip() print(f"Flag: {flag}") except FileNotFoundError: print("No flag found. If you're getting this on the server, message an admin.") print("If you're getting this locally, try on the server!") def help(): print("------------------------") print(f"You have {money} moneyz, 1 moneyz buys 1 swagz") print(f"You have {clothes_count} clothes") print("What do you want?") print("1. Buy clothes") print("2. Sell clothes") print("3. Upgrade clothes") print("4. Assess swag") def buy_clothes(): global money, clothes_count if clothes_count > 9: print("Your wardrobe is full. Maybe one day you can upgrade to a bigger wardrobe.") return False quality = 0 while True: try: quality = int(input("What quality clothes would you like to buy? (1-5)\n> ")) if quality < 1 or quality > 5: print("Invalid input. Quality must be between 1 and 5.") elif quality > money: print("Not enough money to buy this quality of clothes.") else: break except ValueError: print("Invalid input. Please enter a number.") money -= quality clothes.append(quality) clothes_count += 1 return True def sell_clothes(): global money, clothes_count if clothes_count == 0: print("No clothes to sell") return False c = input("Sell your last clothe? (y/n)\n> ").strip().lower() if c != 'y': return False money += clothes[-1] clothes.pop() clothes_count -= 1 return True def queue_upgrade_clothes(): global money, upgrade_quality, upgrade_timer, inprogress_clothe index = -1 quality = 0 while True: try: index = int(input("Cut hole in which clothe?\n> ")) if index < 0 or index >= clothes_count: print("Invalid input. Index out of range.") else: break except ValueError: print("Invalid input. Please enter a number.") while True: try: quality = int(input("How many holes? (1-5)\n> ")) if quality < 1 or quality > 5: print("Invalid input. Quality must be between 1 and 5.") elif quality > money: print("Not enough money to upgrade to this quality.") else: break except ValueError: print("Invalid input. Please enter a number.") money -= quality upgrade_quality = clothes[index] + quality upgrade_timer = quality inprogress_clothe = clothes[index] print(f"Your clothes will be ready in {quality}") return True def apply_upgrade(): global inprogress_clothe, upgrade_quality, upgrade_timer inprogress_clothe = upgrade_quality inprogress_clothe = None upgrade_quality = 0 upgrade_timer = 0 print("Your upgrade is done!") def assess(): swag = sum(clothes) print(f"You have {swag} swagz") if money > 100: print("Ah, a true entrepreneur") print_flag() def menu(): global money option = 0 help() if inprogress_clothe and upgrade_timer > 0: upgrade_timer -= 1 try: option = int(input("> ")) except ValueError: print("Invalid input. Please enter a number.") result = True if option == 1: result = buy_clothes() elif option == 2: result = sell_clothes() elif option == 3: result = queue_upgrade_clothes() elif option == 4: assess() if not result: print("Something went wrong :(") def main(): sys.stdout = open(1, 'w', 1) # Unbuffered output for _ in range(300): menu() print("You died of old age.") if __name__ == "__main__": main()

This Python script replicates the behavior of the C code you provided. It allows you to perform actions such as buying clothes, selling clothes, upgrading clothes, and assessing your swag.

I have this next chall name YooEyyEff with the source code Are you an entrepreneur? Do you have what it takes? nc 0.cloud.chals.io 33146 #include <stdio.h> #include <stdlib.h> int clothes[10]; int clothes_count = 0; int money = 10; int inprogress_clothe = NULL; int upgrade_quality = 0; int upgrade_timer = 0; void print_flag() { char buf[0x80]; FILE file; if ((file = fopen("flag.txt", "r")) != NULL) { fgets(buf, sizeof(buf), file); printf("Flag: %s\n", buf); } else { printf("No flag found. If you're getting this on the server, message an admin.\n" "If you're getting this locally, try on the server!\n"); } } void help() { printf("------------------------\n"); printf("You have %d moneyz, 1 moneyz buys 1 swagz\n", money); printf("You have %d clothes\n", clothes_count); printf("What do you want?\n"); printf("1. Buy clothes\n"); printf("2. Sell clothes\n"); printf("3. Upgrade clothes\n"); printf("4. Assess swag\n"); } int buy_clothes() { if (clothes_count > 9) { printf("Your wardrobe is full. Maybe one day you can upgrade to a bigger wardrobe.\n"); return 0; } int quality = 0; printf("What quality clothes would you like to buy? (1-5)\n"); printf("> "); scanf("%d", &quality); if (money < quality || quality < 1 || quality > 5) return 0; money -= quality; int cloth = malloc(sizeof(int)); cloth = quality; clothes[clothes_count++] = cloth; return 1; } int sell_clothes() { if (clothes_count == 0) { printf("No clothes to sell\n"); return 0; } char c = 0; printf("Sell your last clothe? (y/n)\n"); printf("> "); while (c != 'y' && c != 'n') scanf("%c", &c); if (c != 'y') return 0; money += clothes[clothes_count-1]; free(clothes[--clothes_count]); return 1; } int queue_upgrade_clothes() { int index = -1; int quality = 0; printf("Cut hole in which clothe?\n"); printf("> "); scanf("%d", &index); if (index < 0 || index >= clothes_count) return 0; printf("How many holes? (1-5)\n"); printf("> "); scanf("%d", &quality); if (money < quality || quality < 1 || quality > 5) return 0; money -= quality; upgrade_quality = clothes[index] + quality; upgrade_timer = quality; inprogress_clothe = clothes[index]; printf("Your clothes will be ready in %d\n", quality); return 1; } void apply_upgrade() { inprogress_clothe = upgrade_quality; inprogress_clothe = NULL; upgrade_quality = 0; upgrade_timer = 0; printf("Your upgrade is done!\n"); } void assess() { int swag = 0; for (int i = 0; i < clothes_count; ++i) { swag += *clothes[i]; } printf("You have %d swagz\n", swag); if (money > 100) { printf("Ah, a true entrepreneur\n"); print_flag(); } } void menu() { int option = 0; help(); if (inprogress_clothe && --upgrade_timer == 0) apply_upgrade(); printf("> "); scanf("%d", &option); int result = 1; switch(option) { case 1: result = buy_clothes(); break; case 2: result = sell_clothes(); break; case 3: result = queue_upgrade_clothes(); break; case 4: assess(); break; default: break; } if (!result) { printf("Something went wrong :(\n"); } } int main() { setvbuf(stdout, NULL, _IONBF, 0); for (int i = 0; i < 300; ++i) { menu(); } printf("You died of old age.\n"); return 0; } expand_more i need it in python script
avatar
Ewakaa
Shared 1 prompt
Created 1 year ago
  • I am gebuinely delighteed too glaznce at ths weblog pposts wbich includes tons off valuable facts, thanks ffor pproviding thes kinds of information. - xxxtubebest.com/xPkWWoG6uV7k - 1 month ago

Leave a Comment

Related Tag Prompts

94
0
392
15
0
0
Python classes explained.
1 year ago 2023-03-12 18:13:53 Blank
0
0
code
1 year ago 2023-03-13 21:09:33 TipTip
0
0
comp
1 year ago 2023-03-14 06:56:25 arshiya
0
0
Learning AI as Engineer
1 year ago 2023-03-15 03:44:13 John D
0
0
Python
1 year ago 2023-03-21 21:04:23 Hashaam
0
0
Coding Coach
1 year ago 2023-03-22 07:00:26 Atank
0
0
Generate dummy image
1 year ago 2023-03-23 05:02:01 Prince Kumar
0
0
0
0
Expert Command Block
1 year ago 2023-03-23 05:02:01 Postary
0
0
Clean code
1 year ago 2023-03-23 05:02:01 Ricardorg
0
0
0
0
Model Response Analysis
1 year ago 2023-03-23 15:48:36 Maksim
0
0
0
0
CAN (expert coder
1 year ago 2023-03-26 09:56:03 nobody65534
0
0
🤖Developer AI Assistance
1 year ago 2023-03-26 18:25:19 Javohir
0
0
Backend Developer Interview Questions
1 year ago 2023-03-28 03:41:27 aman
0
0
CSS Coding Assistance
1 year ago 2023-03-28 10:54:37 saad
0
0
0
0
Programmer RP
1 year ago 2023-03-30 05:33:10 Dev
0
0
Jira API with Python threads
1 year ago 2023-03-30 18:09:06 Elvar
0
0
Make more concise coding block
1 year ago 2023-04-07 17:51:16 Yostin