-
-
Save rick2600/1a815905cf2dd8bca5e4a98e27144e6d to your computer and use it in GitHub Desktop.
chall0.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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