How to check if a user input is between a certain range

For a project I am working on I am asked to get a users input and make sure that it is between 0,1. I am not sure the best way to go about this. The variable is z that the user is inputting

2 commentaires

Inputting how? Via command line or in a GUI?
It seems to just be a simple case of using > and < and firing off an appropriate message if it is outside the range though.
using a z = input('Please input....: ')

Connectez-vous pour commenter.

Réponses (1)

James Tursa
James Tursa le 14 Mar 2018
Modifié(e) : James Tursa le 14 Mar 2018

0 votes

Use an "if test" combined with the results of the expressions z > 0 and z < 1 (or possibley z >= 0 and z <= 1 depending on what is meant by "between" in your problem statement). Look at the doc for "if" to see examples of using an "if test".

Catégories

En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by