Yanlax
@Yanlax

Как сделать, чтоб он сначала задавал вопрос,а потом вызывал определенную функцию?

import pyshorteners
import os
import platform
import qrcode


class URL():
    
    action = int(input(" What to do? (1.QrCode 2.ShortUrl) "))

    def short_url():

        url = input(" URL: ")
        n = input(" Choice service ( 1:Os.db, 2:Chilp.it, 3:Da.gd, 4:Is.gd, 5:Qps.ru, 6:TinyURL.com):  ")

        if n == str(1):
            s = pyshorteners.Shortener()
            f = s.osdb.short(url)
            print(" Short URL: ",f)
        elif n == str(2):
            s = pyshorteners.Shortener()
            short_url = s.chilpit.short(url)
            print(" Short URL: ",short_url)
        elif n == str(3):
            s = pyshorteners.Shortener()
            abz = s.dagd.short(url)
            print(" Short URL: ",abz)
        elif n == str(4):
            s = pyshorteners.Shortener()
            abv = s.isgd.short(url)
            print(" Short URL: ",abv)
        elif n == str(5):
            s = pyshorteners.Shortener()
            abh = s.qpsru.short(url)
            print(" Short URL: ",abh)
        elif n == str(6):
            s = pyshorteners.Shortener()
            abk = s.tinyurl.short(url)
            print(" Short URL: ",abk)
        else:
            print(' Error ')

    short_url()


    def qr_code():

        URL = input(" URL: ")
        file = input(" Enter file name:")

        filename = file +".png"

        img = qrcode.make(URL)
        img.save(filename)

    qr_code()

    if action == 1:
        qr_code()
    elif action == 2:
        short_url()
    else:
        print(" Error ")
  • Вопрос задан
  • 98 просмотров
Пригласить эксперта
Ответы на вопрос 1
InternetMaster
@InternetMaster
Интернет
Так высунь функции из простого кода и используй их только в конце где "if".
import pyshorteners
import os
import platform
import qrcode


class URL():
    
    action = int(input(" What to do? (1.QrCode 2.ShortUrl) "))

    def short_url():

        url = input(" URL: ")
        n = input(" Choice service ( 1:Os.db, 2:Chilp.it, 3:Da.gd, 4:Is.gd, 5:Qps.ru, 6:TinyURL.com):  ")

        if n == str(1):
            s = pyshorteners.Shortener()
            f = s.osdb.short(url)
            print(" Short URL: ",f)
        elif n == str(2):
            s = pyshorteners.Shortener()
            short_url = s.chilpit.short(url)
            print(" Short URL: ",short_url)
        elif n == str(3):
            s = pyshorteners.Shortener()
            abz = s.dagd.short(url)
            print(" Short URL: ",abz)
        elif n == str(4):
            s = pyshorteners.Shortener()
            abv = s.isgd.short(url)
            print(" Short URL: ",abv)
        elif n == str(5):
            s = pyshorteners.Shortener()
            abh = s.qpsru.short(url)
            print(" Short URL: ",abh)
        elif n == str(6):
            s = pyshorteners.Shortener()
            abk = s.tinyurl.short(url)
            print(" Short URL: ",abk)
        else:
            print(' Error ')

    def qr_code():

        URL = input(" URL: ")
        file = input(" Enter file name:")

        filename = file +".png"

        img = qrcode.make(URL)
        img.save(filename)

    if action == 1:
        qr_code()
    elif action == 2:
        short_url()
    else:
        print(" Error ")
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы