Skip to content

Instantly share code, notes, and snippets.

@rick2600
Created Aug 30, 2021
Embed
What would you like to do?
chall0.py
import os
import sys
def show_account_info(account):
print("="*80)
print("Name: {}\nMoney: {}".format(account['name'], account['money']))
def read_input(s):
if sys.version_info.major == 2:
return raw_input(s)
elif sys.version_info.major == 3:
return input(s)
def buy_items(account):
bought = False
print("="*80)
items = [
{'name': 'web hacking book', 'price': 100.0},
{'name': 'severino license', 'price': 50.0},
{'name': 'home made hacking tool', 'price': 200.0},
{'name': 'shell', 'price': 1000000000.0},
]
for i in range(len(items)):
print("{}: {} {}".format(i, items[i]['name'].ljust(40), items[i]['price']))
choice = int(read_input("\nitem id? "))
if choice >= 0 and choice <= 3:
how_many = float(read_input("how many? "))
total = items[choice]['price'] * how_many
item_name = items[choice]['name']
if how_many <= 0:
print(":/")
else:
if total > account['money']:
print("You do not have enough money :(")
else:
account['money'] -= total
print("You bought {} of '{}'".format(how_many, item_name))
if item_name == 'shell':
os.system("/bin/sh")
else:
print("Invalid!")
def main():
account = {'name': '', 'money': 1000.0}
account['name'] = read_input("Name? ")
while True:
print("\n0. buy items")
print("1. show account info")
print("2. exit")
choice = read_input("? ")
if choice == '0':
buy_items(account)
elif choice == '1':
show_account_info(account)
elif choice == '2':
break
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment