Here is my python code:
def output(carbs, fat, pro, fiber):
carbs = carbs*4
pro = pro*4
fat = fat*9
fiber = fiber*4
final = carbs + fat + pro - fiber
if(final >= 500):
print("Food: ", "Total Calories: ", final)
elif(final < 100):
print("Food: Salad", "Total Calories: ", final)
elif(final < 500 and final <= 100):
print("Food: Hamburger", "Total Calories: ", final)
def main():
print('''___________ .___ _________ .__ .__ __
\_ _________ ____ __| _/ \_ ___ \_____ | | ____ __ __| | _____ _/ |_
___________
| __)/ _ \ / _ \ / __ | / \ \/\__ \ | | _/ ___\| | | | \__ \\ __/ _ \_
__ \
| \( <_> ( <_> / /_/ | \ \____/ __ \| |_\ \___| | | |__/ __ \| |( <_> |
| \/
\___ / \____/ \____/\____ | \______ (____ |____/\___ |____/|____(____ |__|
\____/|__|
\/ \/ \/ \/ \/ \/ ''')
print("ADD CARBOHYDRATES, FAT, PROTEIN, AND FIBER")
carbs_input = int(input("Carbohydrate content: "))
fat_input = int(input("Fat content: "))
pro_input = int(input("Protein content: "))
fiber_input = int(input("Fiber content: "))
output(carbs, fat, pro, fiber)
main()
Python is telling me that output(carbs, fat, pro, fiber) is not defined. Namely 'carbs'. I think it has to do with the output function.
Any thoughts?
Where are you unclear? Your call to output uses four variables, none of which is defined in that scope. You define variables carbs_input, fat_input, pro_input, fiber_input, but those are the only ones. Try using the variables you defined, instead of those "ghost" variables.
output(carbs_input, fat_input, pro_input, fiber_input)
Related
PROBLEM 1:
how can i remove these external text parts from my ASCII text
in python (i am using pyfiglet ) ? it appears well in VScode
terminal but when i run it from python shell it just appear so
bad like this :
←[33m___________________________________________________←[0m
←[34m ____ _ _ __ __ ______
/ __ \(_)___ ____ _ (_) /_ / / \ \ \ \
/ /_/ / / __ \/ __ `/ / / __/ / / \ \ \ \
/ _, _/ / / / / /_/ / / / /_ /_/ / / / /
/_/ |_/_/_/ /_/\__, / /_/\__/ (_) /_/_/_/
/____/
←[33m←[0m
←[33m___________________________________________________←[0m
←[32m<<< WELCOME TO RING IT APPLICATION >>>
←[0m←[31m
Please enter how many alarms you want to set ?
←[0m
←[95m>>>
here is the header code :
ascii_art = pyfiglet.figlet_format("Ring it ! >>>" , font="slant") + colorama.Fore.YELLOW
ascii_art_colored = colored(ascii_art , "blue")
print(colored("___________________________________________________" , "yellow"))
print("\n\n" +ascii_art_colored + "\n")
print(colored("___________________________________________________" , "yellow")+"\n\n")
print(colored("<<< WELCOME TO RING IT APPLICATION >>>\n" , "green") + colored("\n\nPlease enter how many alarms you want to set ? \n\n" , "red"))
i want to remove these ( ←[33m ←[0m ←[32 )
and it appear like this :
___________________________________________________
____ _ _ __ __ ______
/ __ \(_)___ ____ _ (_) /_ / / \ \ \ \
/ /_/ / / __ \/ __ `/ / / __/ / / \ \ \ \
/ _, _/ / / / / /_/ / / / /_ /_/ / / / /
/_/ |_/_/_/ /_/\__, / /_/\__/ (_) /_/_/_/
/____/
___________________________________________________
<<< WELCOME TO RING IT APPLICATION >>>
Please enter how many alarms you want to set ?
PROBLEM 2 :
also i have an issue with it color ... it just get
cmd theme color not that color i set for it with termcolor2 or
colorama ...
i tried writing this code but had an error. used windows 10 and python 3.8.5
#usage
#python3 coex.py combo.txt extracted.txt
from sys import argv
import re
script , combo_file , ex_file = argv
cfile = open(combo_file)
xfile = open(ex_file, 'w')
def rexmail(cfile):
rexmail = re.compile(r'[a-zA-Z0-9_.+-]+#[a-zA-Z0-9.-]+:[a-zA-Z0-9._-]+')
cfile = rexmail.findall(cfile.read())
lenofclist = len(cfile)
for i in range(lenofclist):
xfile.write("\n")
xfile.write(str(cfile[i]))
print("[+]*********EXTRACTING DONE***********[+]\n")
print("[+]*********CHECK extracted.txt FILE FOR EMAIL:PASS COMBOS*************[+]\n")
def header():
print('''
made with <3
_______ ___ ___ _________ ________ ________ ________ _________ ________ ________
|\ ___ \ |\ \ / /| |\___ ___\ |\ __ \ |\ __ \ |\ ____\ |\___ ___\ |\ __ \ |\ __ \
\ \ __/| \ \ \/ / / \|___ \ \_| \ \ \|\ \ \ \ \|\ \ \ \ \___| \|___ \ \_| \ \ \|\ \ \ \ \|\ \
\ \ \_|/__ \ \ / / \ \ \ \ \ _ _\ \ \ __ \ \ \ \ \ \ \ \ \ \\\ \ \ \ _ _\
\ \ \_|\ \ / \/ \ \ \ \ \ \\ \| \ \ \ \ \ \ \ \____ \ \ \ \ \ \\\ \ \ \ \\ \|
\ \_______\ / /\ \ \ \__\ \ \__\\ _\ \ \__\ \__\ \ \_______\ \ \__\ \ \_______\ \ \__\\ _\
\|_______| /__/ /\ __\ \|__| \|__|\|__| \|__|\|__| \|_______| \|__| \|_______| \|__|\|__|
|__|/ \|__|
EMAIL:PASS extractor from any txt file .
''')
header()
rexmail(cfile)
Error:
Traceback (most recent call last):
File "C:\Users\BRS\Desktop\minecraft\Combo-Extractor-master\coex.py", line 8, in <module>
script , combo_file , ex_file = argv
ValueError: not enough values to unpack (expected 3, got 1)
I dont really get what's off. please help me by correcting this code. and if possible tell me why this happens
is it a problem with tuples or what pls help with this
argv actually return a list whose first element (i.e. index 0 element) is the location of the python file. To correct this error, use
script, combo_file, ex_file = argv[1:]
Alternatively, you can also use _, script, combo_file, ex_file = argv
Relevant Documentation - https://docs.python.org/3/library/sys.html
(Tested on Windows 10 (64 Bit) Python 3.7.4)
I'm trying to make a table from data from a CSV file using only the CSV module. Could anyone tell me what should I do to display the '|' at the end of every row(just after the last element in the row)?
Here's what I have so far:
def display_playlist( filename ):
if filename.endswith('.csv')==False: #check if it ends with CSV extension
filename = filename + ('.csv') #adding .csv if given without .csv extension
max_element_length=0
#aligning columns to the longest elements
for row in get_datalist_from_csv( filename ):
for element in row:
if len(element)>max_element_length:
max_element_length=len(element)
# print(max_element_length)
#return max_element_length
print('-----------------------------------------------------------------------------')
for row in get_datalist_from_csv( filename ):
for element in row:
print('| ', end='')
if (len(element)<=4 and element.isdigit==True):
print(pad_to_length(element,4), end=' |') #trying to get '|' at the end[enter image description here][1]
else:
print(pad_to_length(element, max_element_length), end=' ')
print('\n')
print('-----------------------------------------------------------------------------')
## Read data from a csv format file
def get_datalist_from_csv( filename ):
## Create a 'file object' f, for accessing the file:
with open( filename ) as f:
reader = csv.reader(f) # create a 'csv reader' from the file object
datalist = list( reader ) # create a list from the reader
return datalist # we have a list of lists
## For aligning table columns
## It adds spaces to the end of a string to make it up to length n.
def pad_to_length( string, n):
return string + " "* (n-len(string)) ## s*n gives empty string for n<1
The image I get for now is:
| Track | Artist | Album | Time
| Computer Love | Kraftwerk | Computer World | 7:15
| Paranoid Android | Radiohead | OK Computer | 6:27
| Computer Age | Neil Young | Trans | 5:24
| Digital | Joy Division | Still | 2:50
| Silver Machine | Hawkwind | Roadhawks | 4:39
| Start the Simulator | A-Ha | Foot of the Mountain | 5:11
| Internet Connection | M.I.A. | MAYA | 2:56
| Deep Blue | Arcade Fire | The Suburbs | 4:29
| I Will Derive! | MindofMatthew | You Tube | 3:17
| Lobachevsky | Tom Lehrer | You Tube | 3:04
I would like to use wp_scan to scan my wordpress website for new plugins.
I want to have a python script that show me everyday
a list of vulnerable plugins
a list of new plugins.
To write a parser which give me only the vulnerable plugins of the output is not complicate. But how I can write a parser (or in which way) so that I get only a list of new plugins.
Example - (source of the example - I modified it a little bit http://www.blackmoreops.com/2013/10/14/wpscan-and-quick-wordpress-security/).
First day:
___________________________________________________
__ _______ _____
\ \ / / __ \ / ____|
\ \ /\ / /| |__) | (___ ___ __ _ _ __
\ \/ \/ / | ___/ \___ \ / __|/ _` | '_ \
\ /\ / | | ____) | (__| (_| | | | |
\/ \/ |_| |_____/ \___|\__,_|_| |_| v2.1rNA
WordPress Security Scanner by the WPScan Team
Sponsored by the RandomStorm Open Source Initiative
_____________________________________________________
| URL: http://www.blackmoreops.com/
| Started on Sun Oct 13 13:39:25 2013
[31m[!][0m The WordPress 'http://www.blackmoreops.com/readme.html' file exists
[31m[!][0m Full Path Disclosure (FPD) in 'http://www.blackmoreops.com/wp-includes/rss-functions.php'
[32m[+][0m XML-RPC Interface available under http://www.blackmoreops.com/xmlrpc.php
[32m[+][0m WordPress version 3.6.1 identified from meta generator
[32m[+][0m The WordPress theme in use is twentyten v1.6
| Name: twentyten v1.6
| Location: http://www.blackmoreops.com/wp-content/themes/twentyten/
[32m[+][0m Enumerating plugins from passive detection ...
2 plugins found :
| Name: add-to-any v1.2.5
| Location: http://www.blackmoreops.com/wp-content/plugins/add-to-any/
| Directory listing enabled: Yes
| Readme: http://www.blackmoreops.com/wp-content/plugins/add-to-any/README.txt
| Name: captcha v3.8.4
| Location: http://www.blackmoreops.com/wp-content/plugins/captcha/
| Directory listing enabled: Yes
| Readme: http://www.blackmoreops.com/wp-content/plugins/captcha/readme.txt
[32m[+] Finished at Sun Oct 13 13:39:51 2013[0m
[32m[+] Elapsed time: 00:00:26[0m]
on the next day:
___________________________________________________
__ _______ _____
\ \ / / __ \ / ____|
\ \ /\ / /| |__) | (___ ___ __ _ _ __
\ \/ \/ / | ___/ \___ \ / __|/ _` | '_ \
\ /\ / | | ____) | (__| (_| | | | |
\/ \/ |_| |_____/ \___|\__,_|_| |_| v2.1rNA
WordPress Security Scanner by the WPScan Team
Sponsored by the RandomStorm Open Source Initiative
_____________________________________________________
| URL: http://www.blackmoreops.com/
| Started on Sun Oct 13 13:39:25 2013
[31m[!][0m The WordPress 'http://www.blackmoreops.com/readme.html' file exists
[31m[!][0m Full Path Disclosure (FPD) in 'http://www.blackmoreops.com/wp-includes/rss-functions.php'
[32m[+][0m XML-RPC Interface available under http://www.blackmoreops.com/xmlrpc.php
[32m[+][0m WordPress version 3.6.1 identified from meta generator
[32m[+][0m The WordPress theme in use is twentyten v1.6
| Name: twentyten v1.6
| Location: http://www.blackmoreops.com/wp-content/themes/twentyten/
[32m[+][0m Enumerating plugins from passive detection ...
3 plugins found :
| Name: add-to-any v1.2.5
| Location: http://www.blackmoreops.com/wp-content/plugins/add-to-any/
| Directory listing enabled: Yes
| Readme: http://www.blackmoreops.com/wp-content/plugins/add-to-any/README.txt
| Name: captcha v3.8.4
| Location: http://www.blackmoreops.com/wp-content/plugins/captcha/
| Directory listing enabled: Yes
| Readme: http://www.blackmoreops.com/wp-content/plugins/captcha/readme.txt
| Name: google-analyticator v6.4.5
| Location: http://www.blackmoreops.com/wp-content/plugins/google-analyticator/
| Directory listing enabled: Yes
| Readme: http://www.blackmoreops.com/wp-content/plugins/google-analyticator/readme.txt
[32m[+] Finished at Sun Oct 14 13:39:51 2013[0m
[32m[+] Elapsed time: 00:00:26[0m]
Should I separate the string always after a [+] and compare them all
(I don't know how the list of the output is sorted - I think alpahbetic - so I can't get only the last plugins and say this are my new plugins)? Is that efficient? Making the problem simple:
first string:
Hallo
Pet
Me
second string:
Hallo
World
Pet
Me
How I find out what is the new word in a efficient way?
First you split the string in a list and then print every word in the second string given it is not the first string.
str1 = "Hallo Pet Me"
str2 = "Hallo World Pet Me"
split1 = str1.split()
split2 = str2.split()
print [word for word in split2 if word not in split1]
If you want to ignore differences in lower/uppercase:
str1 = "Hallo Pet Me"
str2 = "Hallo World Pet Me"
split1 = str1.lower().split()
split2 = str2.lower().split()
print [word for word in split2 if word not in split1]
Solving your simplified example:
str1 = "Hallo Pet Me"
str2 = "Hallo World Pet Me"
set1 = set(str1.split())
set2 = set(str2.split())
print set2 - set1
You have two sets of strings and you want to obtain strings that are in the second set but not in the first one.
I'm new to Python. I'm trying to make code it so it will print out this ASCII art traffic light, here is the actual ASCII
##
_[]_
[____]
.----' '----.
.===| .==. |===.
\ | /####\ | /
/ | \####/ | \
'===| `""` |==='
.===| .==. |===.
\ | /::::\ | /
/ | \::::/ | \
'===| `""` |==='
.===| .==. |===.
\ | /&&&&\ | /
/ | \&&&&/ | \
'===| `""` |==='
jgs '--.______.--'
And the Code I'm trying to use is this
print ("##"),
print (" _[]_"),
print (".----' '----."),
print (" .===| .==. |===."),
print (" \ | /####\ | /"),
print (" / | \####/ | \\"),
print ("'===| `""` |==='"),
print (" .===| .==. |===."),
print ("\ | /::::\ | /"),
print (" / | \::::/ | \"),
print ("'===| `""` |==='"),
print (".===| .==. |===."),
print (" \ | /&&&&\ | /"),
print (" / | \&&&&/ | \"),
print (" '===| `""` |==='"),
print ("'--.______.--'")
You need to escape the \ characters, double them:
print (" / | \::::/ | \"),
should be:
print(" / | \\::::/ | \\")
You want to get rid of all the commas too.
Note that you can create a multiline string using triple quotes; make it a raw string (using r'') and you don't have to escape anything either:
print(r''' _[]_
[____]
.----' '----.
.===| .==. |===.
\ | /####\ | /
/ | \####/ | \
'===| `""` |==='
.===| .==. |===.
\ | /::::\ | /
/ | \::::/ | \
'===| `""` |==='
.===| .==. |===.
\ | /&&&&\ | /
/ | \&&&&/ | \
'===| `""` |==='
jgs '--.______.--'
''')