Insights Blog
-- Browse All Articles --
Physics Articles
Physics Tutorials
Physics Guides
Physics FAQ
Math Articles
Math Tutorials
Math Guides
Math FAQ
Education Articles
Education Guides
Bio/Chem Articles
Technology Guides
Computer Science Tutorials
Forums
Chemistry
Biology and Medical
Earth Sciences
Computer Science
Computing and Technology
DIY Projects
Trending
Featured Threads
Log in
Register
What's new
Search
Search
Search titles only
By:
Chemistry
Biology and Medical
Earth Sciences
Computer Science
Computing and Technology
DIY Projects
Menu
Log in
Register
Navigation
More options
Contact us
Close Menu
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Forums
Other Sciences
Programming and Computer Science
Python: printing every other input using a for loop
Reply to thread
Message
[QUOTE="Mark44, post: 6239543, member: 147785"] The first number indicates the number of strings in the sequence of inputs. It should be used to control a for loop that runs that many times, with pairs of input calls. For example, in your sample inputs, the first number entered indicates that three strings will be in the input sequence. Because the rest of the input values alternate between integers and strings, the loop body should do two inputs: the first to input a number and the second to input a string but not do anything with it. Notice that the problem statement says "the rest consists of alternation of string and integer." but the sample input sequence has this alternation in the opposite order. That is, as integer, string, integer, string, and so on. I wrote a short program that appears to satisfy the program requirements, using exactly the sample inputs you wrote. Here is the output from that program. [code]Number of strings: 3 12 Val: 12 tiger 11 Val: 11 cats 10 Val: 10 dogs[/code]The only output from my program are the initial prompt to enter the first number and the lines that start with Val: ... All other lines are what I typed as inputs to the program. [/QUOTE]
Insert quotes…
Post reply
Forums
Other Sciences
Programming and Computer Science
Python: printing every other input using a for loop
Back
Top