Sharpen Your Coding Skills with These 3 Fun Programming Problems for Beginners

Sharpen Your Coding Skills with These 3 Fun Programming Problems for Beginners

Sharpen Your Coding Skills with These 3 Fun Programming Problems for Beginners

Welcome back to Neural Nonsense weekly blog! In this post, we'll be exploring some coding problems that are perfect for challenging your coding skills and improving your problem-solving abilities. These problems are suitable for beginners and advanced coders alike, so don't hesitate to give them a try!

Problem 1: "Word Count"

Write a program that takes in a sentence as input and outputs the number of words in the sentence. Assume that words in the sentence are separated by exactly one space character. For example, if the input is "Hello world", the output should be 2.

Example:

Input:

This is a sentence

Output:

4

Python Solution:

sentence = input()
words = sentence.split()
print(len(words))

C++ Solution:

#include <iostream>
#include <string>
using namespace std;

int main() {
    string sentence;
    getline(cin, sentence);
    int count = 1;
    for (int i=0; i < sentence.length();i++) {
        if (sentence[i] == ' ') {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Problem 2: "Counting Vowels"

Write a program that takes in a string as input and outputs the number of vowels (a, e, i, o, u) in the string. The input string will contain only lowercase letters.

Example:

Input:

hello world

Output:

3

Python Solution:

string = input().lower()
count = 0
for char in string:
    if char in "aeiou":
        count += 1
print(count)

C++ Solution:

#include <iostream>
#include <string>
using namespace std;

int main() {
    string str;
    getline(cin, str);
    int count = 0;
    for (int i=0; i<str.length();i++) {
        char c = str[i];
        if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Problem 3: "Reverse a Sentence"

Write a program that takes in a sentence as input and outputs the sentence with the order of the words reversed. A sentence is defined as a string of words separated by spaces. The input string will contain only letters and spaces, with no punctuation marks.

Example:

Input:

The quick brown fox jumps over the lazy dog

Output:

dog lazy the over jumps fox brown quick The

Python Solution:

sentence = input().split()
sentence.reverse()
output = " ".join(sentence)
print(output)

C++ Solution:

#include <iostream>
#include <vector>
#include <sstream>
using namespace std;

int main() {
    string sentence;
    getline(cin, sentence);
    vector<string> words;
    stringstream ss(sentence);
    string word;
    while (ss >> word) {
        words.push_back(word);
    }
    for (int i = words.size()-1; i >= 0; i--) {
        cout << words[i] << " ";
    }
    cout << endl;
    return 0;
}

Conclusion

I hope you enjoyed solving these programming problems! Whether you are a beginner or an experienced programmer, it's always a good idea to challenge yourself and practice your skills. Remember that programming is all about problem-solving and perseverance, so don't give up if you find a problem difficult at first. Take a break, come back to it later, and keep trying until you find a solution.

If you liked these problems, there are many more programming challenges and exercises out there that you can try. Don't be afraid to explore and experiment with different programming languages, libraries, and tools, and don't hesitate to ask for help or advice from your peers and mentors. The programming community is a friendly and supportive one, and there's always something new to learn and discover.

Thank you for following me on this programming journey, and I wish you all the best in your future coding endeavors. Keep coding, keep learning, and keep having fun!

"image"

Did you find this article valuable?

Support Mojtaba Maleki by becoming a sponsor. Any amount is appreciated!