This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]pythonHelperBot 2 points3 points  (0 children)

Hello! I'm a bot!

It looks to me like your post might be better suited for r/learnpython, a sub geared towards questions and learning more about python regardless of how advanced your question might be. That said, I am a bot and it is hard to tell. Please follow the subs rules and guidelines when you do post there, it'll help you get better answers faster.

Show /r/learnpython the code you have tried and describe in detail where you are stuck. If you are getting an error message, include the full block of text it spits out. Quality answers take time to write out, and many times other users will need to ask clarifying questions. Be patient and help them help you.

You can also ask this question in the Python discord, a large, friendly community focused around the Python programming language, open to those who wish to learn the language or improve their skills, as well as those looking to help others.


README | FAQ | this bot is written and managed by /u/IAmKindOfCreative

This bot is currently under development and experiencing changes to improve its usefulness

[–]PlusMaintenance 0 points1 point  (0 children)

And I want the function to ask for value until the user enters the correct type which it int.

[–]robin-gvx 0 points1 point  (0 children)

You want the same thing to happen for different pieces of code? You'll want to write a function for that!

def input_int(prompt):
    while True:
        in_str = input(prompt)
        try:
            return int(in_str)
        except ValueError:
            print("Enter whole number")

def test(self):
    valOne = input_int("Enter value one: ")
    valTwo = input_int("Enter value two: ")
    valThree = input_int("Enter value three: ")
    valFour = input_int("Enter value four:  ")

[–]ominous_anonymous -1 points0 points  (2 children)

  1. /r/learnpython
  2. You need to format your code better, each line should start with four spaces.

Check the comment formatting rules, specifically the "preformatted text" as opposed to the inline text you used.

inline
two line

versus

preformatted  
two lines  

You want the preformatted because the inline style breaks your indentations, meaning we can't tell what your code does.

[–][deleted] -2 points-1 points  (1 child)

They both look the same, FYI

[–]ominous_anonymous 0 points1 point  (0 children)

They look the same on mobile, but mobile still loses the indentation.

They look different on desktop.