jobbole / programmingprojectlist Goto Github PK
View Code? Open in Web Editor NEW程序员练手小项目
程序员练手小项目
print 'kill game by input end'
refdoc=['a','e','i','o','u'];
while 1:
s=input("input string:");
if s=='end':
print 'end game';
break;
if s[0] not in refdoc:
s1=s[1:]+'-'+s[0]+"ay";
print s1;
希望可以给每个练手项目配上开源代码
感谢
`import sys,tkFileDialog,os
from Tkinter import*
class Note():
def init(self):
self.fname=None; #GUI document addr
self.tk=Tk()
self.createUI()
self.tk.mainloop()
def createUI(self):
menubar=Menu(self.tk)
fmenu=Menu(menubar,tearoff=0)
fmenu.add_command(label='Open',command=self.open) #bind menu and function
fmenu.add_command(label='Save',command=self.save)
fmenu.add_command(label='Exit',command=exit)
menubar.add_cascade(label="File",menu=fmenu)
self.tk.config(menu=menubar)
self.text=Text()
self.text.pack()
def save(self):
print 'save file'
txtContent = self.text.get(1.0,END)
self.saveFile(content=txtContent)
def open(self):
print 'open file'
self.filename=tkFileDialog.askopenfilename(initialdir = os.getcwd())
filecontent=self.openFile(fname=self.filename)
if filecontent is not -1:
self.text.delete(1.0,END)
self.text.insert(1.0,filecontent)
def openFile(self,fname=None):
if fname is None:
return -1;
self.fname=fname;
file=open(fname,'r+')
content = file.read()
file.close()
return content
def saveFile(self,content=None):
if content is None:
return -1
if self.fname is None : #new file create addr need sudo permission
self.fname=tkFileDialog.asksaveasfilename(initialdir = os.getcwd());
file=open(self.fname,'w')
file.write(content)
file.flush()
file.close()
return 0
def exit(self):
sys.exit(0)
if name=='main':
Note();
`
后续还有项目代码更新么⊙∀⊙?
print 'kill game by input end'
while 1:
s=input("input string:")
if s== 'end':
break;
s1='';
index=0;
l=len(s);
while index<l:
s1=s1+s[l-index-1];
index=index+1;
if s1==s:
print 'the string is a palindrome'
else:
print 'the string is not a palindrome'
#!/usr/bin/env python #encoding=utf-8 print 'kill game by input end' while 1: s=input("input string:") if s== 'end': break; s1=''; index=0; l=len(s); print s[l-index-1]; while index<l: s1=s1+s[l-index-1]; index=index+1; print s1
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str("");
string newStr("");
cout << "input your message :";
cin >> str;
for (int i = (str.length() - 1); i >= 0; i--) {
newStr += str[i];
}
cout << newStr << endl;
cin.ignore(6);
}
print 'kill game by input end' refdoc=['a','e','i','o','u']; while 1: numbera=0; numbere=0; numberi=0; numbero=0; numberu=0; s=input("input string:"); if s=='end': print 'end game'; break; for i in s: if i in refdoc: if i==refdoc[0]: numbera=numbera+1; elif i==refdoc[1]: numbere=numbere+1; elif i==refdoc[2]: numberi=numberi+1; elif i==refdoc[3]: numbero=numbero+1; else: numberu=numberu+1; print 'the vowel a numbers is '+str(numbera); print 'the vowel e numbers is '+str(numbere); print 'the vowel i numbers is '+str(numberi); print 'the vowel o numbers is '+str(numbero); print 'the vowel u numbers is '+str(numberu);
`#!/usr/bin/env python
#encoding=utf-8
import re
import string
print 'kill game by input end'
f=open("python_string_test.txt"); #count file
result=0;
identify=string.maketrans('','')
delEstr = string.punctuation + string.digits; #remove pounction and digit
for line in f.readlines(): #count each line
cleanline=line.translate(identify,delEstr);
lineArr = re.split(' ',cleanline);
index=0;
temp=[];
#remove '\n',''
while index<len(lineArr):
if lineArr[index]=='\n':
temp.append(str(index))
if lineArr[index]=='':
temp.append(str(index))
index=index+1;
index=0;
while index<len(temp):
lineArr.pop(len(temp)-index-1);
index=index+1;
result=result+len(lineArr);
print str(result); #result
`
import java.util.Scanner;
public class Reverse {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("input your date:");
StringBuffer buf = new StringBuffer(scanner.nextLine());
buf.reverse();
System.out.println("your data:" + buf.toString());
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.