Can't print a quiz on my webapp, it either doesn't display or displays in Pycharm

So I have this quiz to calculate how attractive someone is, and I want to make a web app so people can use it, problem is, either the code executes in PyCharm only or it doesn’t print nowhere at all. I want it to print this directly into the streamlit webapp so it works exactly the same it works in pycharm. Thanks in advance!

# Introduction
import streamlit

def start():
    from time import sleep

    print("SMV Calculator Version 1.0")
    sleep(1)

    print("Hello, today we will calculate precisely how attractive you are out of 10")
    sleep(3)

    print(""
          "")
    print("The results you receive will likely be shocking, don't get offended.")
    sleep(3)

    print(""
          "")
    print(
        "You will receive a short term value (...) and a long term value (...)")
    sleep(3)

    print(""
          "")
    print("We will ask you questions about your characteristics in intergender and relationship scenarios")
    sleep(3)

    print(""
          "")
    print("PLEASE BE COMPLETELY HONEST, UNHONEST ANSWERS MEANS UNHONEST RESULTS!")
    sleep(3)

    selection = str(input("Please type in your gender (0 for male and 1 for female) to start! "))
    if selection == "0":
        maleagepoints = 0
        from smvapp import malevariables
    elif selection == "1":
        femaleagepoints = 0
        from smvapp import femalevariables
    elif selection != "0" or "1":
        print("You literally had one job, to enter one or zero... Refresh and listen to directions.")

print(streamlit.title(start()))

(

Hi @naisukhy ,

In order to print on your web application, please use streamlit.write function . It seems like you haven’t used it anywhere, if I’m not wrong.

cheers
Avra

It doesn’t work. Only executes in pycharm and not the web app

streamlit.write(start())
# start is the function that is supposed to print everything that needs to be printed

Ran this code and got nothing.

Hi @naisukhy ,

In order to print your lines within the web application, you need to use st.write syntax. Similarly, in case of intereactive input, you can also use, st.text_input widget . Please refer to the doc for a quick start. Below a relavant snippet.

import streamlit as st

# Get user input 
value = st.number_input(label = "Please enter 0  or 1 to start!",min_value = 0, max_value = 1, value = 1)
if value == 0 :
   st.write("User is Unhapppy :worried:") # Print within the app
else:
   st.write("User is Happy :grinning:")

Hope this helps. Goodluck !
Avra

Alright, thanks. I’ll keep you updated

1 Like

Alright, it seems as if I have to turn all of my python functions into streamlit functions, such a print and input, etc., is that right?

1 Like

Exactly! Please use Streamlit syntax. For example - instead of input, use streamlit widget (number_input, text_input etc) or instead of print, use write or markdown - streamlit syntax. Do refer to the doc as well for more information .In that way, your codes will start to interact within the web app, and you can build one !
Cheers
Avra

1 Like