Trying to have an output repeat

  • Thread starter Thread starter magnifik
  • Start date Start date
  • Tags Tags
    Output
Click For Summary
SUMMARY

The discussion focuses on creating a function in programming that takes a string input formatted as "Ny" (where N is a number) and outputs the character 'y' repeated N times. The challenge highlighted is the need for clear specifications to differentiate between inputs like '33y' (which could imply either 'y' repeated 33 times or '3y' repeated 3 times). Participants suggest using string manipulation techniques and parsing functions to achieve the desired output effectively.

PREREQUISITES
  • Understanding of string manipulation in programming languages.
  • Familiarity with functions and their syntax in a chosen programming language.
  • Basic knowledge of input parsing techniques.
  • Experience with conditional logic to handle ambiguous input formats.
NEXT STEPS
  • Research string manipulation functions in Python, such as `str.repeat()`.
  • Learn about regular expressions for input parsing in JavaScript.
  • Explore function overloading in C++ to handle different input formats.
  • Study error handling techniques to manage ambiguous user inputs effectively.
USEFUL FOR

Programmers, software developers, and anyone interested in string processing and input validation in their applications.

magnifik
Messages
350
Reaction score
0
How do you make a string repeat itself for a given number of times?
For example, if I wanted to make "3y" print out "yyy" on the screen (it prints "y" 3 times because the number in the input is 3).. how would i do this using functions?
 
Physics news on Phys.org
you could just parse the input string; but of course, you will need to include some specifications, or the input/output you want can be very vague ('33y') can be 33 times of y or 3 times of 3y.
 

Similar threads

Replies
7
Views
3K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 22 ·
Replies
22
Views
6K
Replies
20
Views
4K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 31 ·
2
Replies
31
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K