用户定义的功能未在Web应用上显示的结果

发布于 2025-02-12 04:50:13 字数 721 浏览 1 评论 0原文

我正在尝试定义将金额除以天数的功能。 到目前为止,用户可以提交值,但我不知道如何在简化的Web应用程序上显示结果显示。 我在下面复制了一部分代码。 PS我也是Python的完整初学者。 感谢您的帮助

#HOW OFTEN EAT OUT
st.write("2. How often do you eat out?") 
form04 = st.form(key='form04')
days = form04.text_input('Please enter average number of days')
submit04 = form04.form_submit_button('Submit')
#HOW MUCH INCOME
if submit04:
  st.write('3. What is your monthly income?') 
  form05 = st.form(key='form05')
  income = form05.text_input('Please enter monthly income')
  submit05 = form05.form_submit_button('Submit')  
  if submit05:
      def idealbudget(days, income):
          budget=float(income)/float(days)
          return float(budget)
          st.write('Result is', budget)

I am trying to define a function that divides Amount of money by Number of days.
So far the user can submit values, but I don't know how to make the result display on my Streamlit web app.
I copied part of my code below.
P.S. I am also a complete beginner in Python.
Thanks for any help

#HOW OFTEN EAT OUT
st.write("2. How often do you eat out?") 
form04 = st.form(key='form04')
days = form04.text_input('Please enter average number of days')
submit04 = form04.form_submit_button('Submit')
#HOW MUCH INCOME
if submit04:
  st.write('3. What is your monthly income?') 
  form05 = st.form(key='form05')
  income = form05.text_input('Please enter monthly income')
  submit05 = form05.form_submit_button('Submit')  
  if submit05:
      def idealbudget(days, income):
          budget=float(income)/float(days)
          return float(budget)
          st.write('Result is', budget)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱格式化 2025-02-19 04:50:14

在此代码段中,您定义了一个函数,但您从未真正调用它:

  if submit05:
      def idealbudget(days, income):
          budget=float(income)/float(days)
          return float(budget)
          st.write('Result is', budget)

此外,您的st.Write呼叫的标签不正确,它应该与def 语句。工作解决方案可能看起来像以下(未经测试):

  if submit05:
      def idealbudget(days, income):
          budget=float(income)/float(days)
          return float(budget)

      st.write('Result is', idealbudget(days, income))

In this code snippet, you define a function but you never actually call it:

  if submit05:
      def idealbudget(days, income):
          budget=float(income)/float(days)
          return float(budget)
          st.write('Result is', budget)

Additionally, your st.write call is tabbed incorrectly, it should be at the same level as the def statement. A working solution probably looks like the following (untested):

  if submit05:
      def idealbudget(days, income):
          budget=float(income)/float(days)
          return float(budget)

      st.write('Result is', idealbudget(days, income))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文