Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to show error in a field without text (Empty)

I have a small problem with the empty field (without text) in the api in the description field, I would like that when searching for a kind of weapon it appears that it does not have a description

This is the code I’m using:

import json
import requests

args = input("Escribe: ")
rarity = input("rareza: ")





response = requests.get("https://jose89fcb.es/apifortnite/weapons.php")
data = response.json()



for api in data['weapons']:
    if args == api["name"].strip():
     if rarity == api["rarity"]:
        
        print(f'Desc: {api["description"]}')

In this case, the empty field is in the description and I would like an error "No description" to appear.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Could someone help me, thank you very much!

>Solution :

Try to check if it is empty:

import json
import requests

args = input("Escribe: ")
rarity = input("rareza: ")

response = requests.get("https://jose89fcb.es/apifortnite/weapons.php")
data = response.json()

for api in data['weapons']:
    if args == api["name"].strip():
     if rarity == api["rarity"]:
        description = api["description"]
        if description:
            print(f'Desc: {description}')
        else:
            print("No description")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading